mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-29 12:03:03 +00:00
Bring in timespce_get form NetBSD.
Bring in the functionality for timespec_get from NetBSD. I've lightly edited the .c file to remove _DIAGASSERT because FreeBSD doesn't have that functionality and the typical #define'ing it to assert isn't right here. The man page is verbatim from NetBSD, but will be revised as part of a larger cleanup of the time man pages (they are inconsistent and vague in all the wrong places). Differential Review: https://reviews.freebsd.org/D16649
This commit is contained in:
parent
f4d5e7d8b5
commit
7e299411ac
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=337576
@ -206,6 +206,11 @@ time_t posix2time(time_t t);
|
||||
#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
|
||||
#include <xlocale/_time.h>
|
||||
#endif
|
||||
|
||||
/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */
|
||||
#define TIME_UTC 1 /* time elapsed since epoch */
|
||||
int timespec_get(struct timespec *ts, int base);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_TIME_H_ */
|
||||
|
@ -135,6 +135,7 @@ SRCS+= __getosreldate.c \
|
||||
termios.c \
|
||||
time.c \
|
||||
times.c \
|
||||
timespec_get.c \
|
||||
timezone.c \
|
||||
tls.c \
|
||||
ttyname.c \
|
||||
@ -299,6 +300,7 @@ MAN+= alarm.3 \
|
||||
tcsetsid.3 \
|
||||
time.3 \
|
||||
times.3 \
|
||||
timespec_get.3 \
|
||||
timezone.3 \
|
||||
ttyname.3 \
|
||||
tzset.3 \
|
||||
|
@ -420,6 +420,7 @@ FBSD_1.5 {
|
||||
scandir_b;
|
||||
sem_clockwait_np;
|
||||
setproctitle_fast;
|
||||
timespec_get;
|
||||
};
|
||||
|
||||
FBSDprivate_1.0 {
|
||||
|
76
lib/libc/gen/timespec_get.3
Normal file
76
lib/libc/gen/timespec_get.3
Normal file
@ -0,0 +1,76 @@
|
||||
.\" $NetBSD: timespec_get.3,v 1.2 2016/10/04 10:46:40 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Kamil Rytarowski.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 4, 2016
|
||||
.Dt TIMESPEC_GET 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm timespec_get
|
||||
.Nd get current calendar time
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In time.h
|
||||
.Vt #define TIME_UTC 1
|
||||
.Ft int
|
||||
.Fn timespec_get "struct timespec *ts" "int base"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
function sets the interval pointed to by
|
||||
.Fa ts
|
||||
to hold the current calendar time based on the specified time base in
|
||||
.Fa base .
|
||||
.Pp
|
||||
Currently the only supported valid base is
|
||||
.Dv TIME_UTC .
|
||||
It returns time elapsed since epoch.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Nm
|
||||
function returns the passed value of
|
||||
.Fa base
|
||||
if successful, otherwise
|
||||
.Dv 0
|
||||
on failure.
|
||||
.\" .Sh ERRORS
|
||||
.Sh SEE ALSO
|
||||
.Xr clock_gettime 2
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
function conforms to
|
||||
.St -isoC-2011 .
|
||||
.Sh HISTORY
|
||||
This interface first appeared in
|
||||
.Nx 8 .
|
||||
.Sh AUTHORS
|
||||
.An Kamil Rytarowski Aq Mt kamil@NetBSD.org
|
57
lib/libc/gen/timespec_get.c
Normal file
57
lib/libc/gen/timespec_get.c
Normal file
@ -0,0 +1,57 @@
|
||||
/* $NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2016 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Kamil Rytarowski.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $");
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <assert.h>
|
||||
#include <time.h>
|
||||
|
||||
/* ISO/IEC 9899:201x 7.27.2.5 The timespec_get function */
|
||||
|
||||
int
|
||||
timespec_get(struct timespec *ts, int base)
|
||||
{
|
||||
|
||||
/* _DIAGASSERT(ts != NULL); */
|
||||
|
||||
switch (base) {
|
||||
case TIME_UTC:
|
||||
if (clock_gettime(CLOCK_REALTIME, ts) == -1)
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
@ -60,7 +60,7 @@
|
||||
* in the range 5 to 9.
|
||||
*/
|
||||
#undef __FreeBSD_version
|
||||
#define __FreeBSD_version 1200076 /* Master, propagated to newvers */
|
||||
#define __FreeBSD_version 1200077 /* Master, propagated to newvers */
|
||||
|
||||
/*
|
||||
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
|
||||
|
Loading…
Reference in New Issue
Block a user