diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2018-10-30 16:28:43 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2018-10-30 16:28:43 +0000 |
commit | 1cf268a2ea3ddde5672c28ea4325f04d7f8594d4 (patch) | |
tree | d6c233ed4e557d09379ade91dc90884e7ad86857 | |
parent | 109dc65ae659f99838c64a6aea35a88efd11e3c4 (diff) |
Add C11's timespec_get(3); minor bump for libc.
Tweaked diff from brad@
manpage tweaks florian@ and jmc@
ok deraadt@ millert@
-rw-r--r-- | include/time.h | 11 | ||||
-rw-r--r-- | lib/libc/Symbols.list | 1 | ||||
-rw-r--r-- | lib/libc/gen/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/gen/timespec_get.3 | 85 | ||||
-rw-r--r-- | lib/libc/gen/timespec_get.c | 48 | ||||
-rw-r--r-- | lib/libc/hidden/time.h | 3 | ||||
-rw-r--r-- | lib/libc/shlib_version | 2 |
7 files changed, 149 insertions, 7 deletions
diff --git a/include/time.h b/include/time.h index fc9121e631d..51bee8fe771 100644 --- a/include/time.h +++ b/include/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.30 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: time.h,v 1.31 2018/10/30 16:28:42 guenther Exp $ */ /* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */ /* @@ -70,7 +70,7 @@ typedef __size_t size_t; #define CLOCKS_PER_SEC 100 /* frequency of ticks reported by clock(). */ -#if __POSIX_VISIBLE >= 199309 +#if __POSIX_VISIBLE >= 199309 || __ISO_C_VISIBLE >= 2011 #ifndef _TIMESPEC_DECLARED #define _TIMESPEC_DECLARED struct timespec { @@ -78,7 +78,9 @@ struct timespec { long tv_nsec; /* and nanoseconds */ }; #endif +#endif +#if __POSIX_VISIBLE >= 199309 #include <sys/_time.h> #ifndef _CLOCKID_T_DEFINED_ @@ -173,6 +175,11 @@ size_t strftime_l(char *__restrict, size_t, const char *__restrict, __attribute__ ((__bounded__(__string__,1,2))); #endif +#if __ISO_C_VISIBLE >= 2011 +#define TIME_UTC 1 /* time elapsed since epoch */ +int timespec_get(struct timespec *_ts, int _base); +#endif + #if __BSD_VISIBLE void tzsetwall(void); time_t timelocal(struct tm *); diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list index 7c100000979..527f1f80be4 100644 --- a/lib/libc/Symbols.list +++ b/lib/libc/Symbols.list @@ -429,6 +429,7 @@ timer_delete timer_getoverrun timer_gettime timer_settime +timespec_get thrkill truncate umask diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index cda5fccfcb3..107fe4889ae 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.78 2018/01/12 04:36:12 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.79 2018/10/30 16:28:42 guenther Exp $ # gen sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen @@ -22,7 +22,7 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \ siginterrupt.c siglist.c signal.c signame.c \ sigsetops.c sleep.c statvfs.c strtofflags.c sysconf.c \ syslog.c syslog_r.c telldir.c time.c times.c \ - tolower_.c tree.c ttyname.c \ + timespec_get.c tolower_.c tree.c ttyname.c \ ttyslot.c toupper_.c ualarm.c uname.c unvis.c usleep.c \ utime.c valloc.c vis.c wait.c wait3.c waitpid.c warn.c \ warnc.c warnx.c vwarn.c vwarnc.c vwarnx.c verr.c verrc.c verrx.c @@ -53,5 +53,5 @@ MAN+= __tfork_thread.3 alarm.3 auth_subr.3 authenticate.3 basename.3 clock.3 \ scandir.3 setjmp.3 setmode.3 setproctitle.3 shm_open.3 \ siginterrupt.3 signal.3 \ sigaddset.3 sleep.3 statvfs.3 sysconf.3 strtofflags.3 \ - syslog.3 time.3 times.3 toascii.3 tolower.3 toupper.3 \ + syslog.3 time.3 times.3 timespec_get.3 toascii.3 tolower.3 toupper.3 \ ttyname.3 ualarm.3 uname.3 unvis.3 usleep.3 utime.3 valloc.3 vis.3 diff --git a/lib/libc/gen/timespec_get.3 b/lib/libc/gen/timespec_get.3 new file mode 100644 index 00000000000..ea4771753d1 --- /dev/null +++ b/lib/libc/gen/timespec_get.3 @@ -0,0 +1,85 @@ +.\" $OpenBSD: timespec_get.3,v 1.1 2018/10/30 16:28:42 guenther Exp $ +.\" $NetBSD: timespec_get.3,v 1.4 2018/08/13 06:08:48 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. +.\" +.Dd August 10, 2018 +.Dt TIMESPEC_GET 3 +.Os +.Sh NAME +.Nm timespec_get +.Nd get current calendar time +.Sh SYNOPSIS +.In time.h +.Ft int +.Fn timespec_get "struct timespec *ts" "int base" +.Sh DESCRIPTION +The +.Fn timspec_get +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 +The base +.Dv TIME_UTC +returns the time since the Epoch. +This time is expressed in seconds and nanoseconds since midnight (0 hour), +January 1, 1970. +In +.Ox , +this corresponds to +.Dv CLOCK_REALTIME . +.Sh RETURN VALUES +The +.Nm +function returns the passed value of +.Fa base +if successful, otherwise +.Dv 0 +on failure. +.Sh SEE ALSO +.Xr clock_gettime 2 , +.Xr gettimeofday 2 , +.Xr time 3 +.Sh STANDARDS +The +.Nm +function with a +.Fa base +of +.Dv TIME_UTC +conforms to +.St -isoC-2011 . +.Sh HISTORY +The +.Fn timespec_get +function was ported from +.Nx +and first appeared in +.Ox 6.5 . diff --git a/lib/libc/gen/timespec_get.c b/lib/libc/gen/timespec_get.c new file mode 100644 index 00000000000..520a5954025 --- /dev/null +++ b/lib/libc/gen/timespec_get.c @@ -0,0 +1,48 @@ +/* $OpenBSD: timespec_get.c,v 1.1 2018/10/30 16:28:42 guenther Exp $ */ +/* $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 <time.h> + +int +timespec_get(struct timespec *ts, int base) +{ + switch (base) { + case TIME_UTC: + if (clock_gettime(CLOCK_REALTIME, ts) == -1) + return 0; + break; + default: + return 0; + } + + return base; +} diff --git a/lib/libc/hidden/time.h b/lib/libc/hidden/time.h index e777020335b..18c49f8fcb9 100644 --- a/lib/libc/hidden/time.h +++ b/lib/libc/hidden/time.h @@ -1,4 +1,4 @@ -/* $OpenBSD: time.h,v 1.5 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: time.h,v 1.6 2018/10/30 16:28:42 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther <guenther@openbsd.org> * @@ -47,6 +47,7 @@ PROTO_NORMAL(time); PROTO_DEPRECATED(timegm); PROTO_DEPRECATED(timelocal); PROTO_DEPRECATED(timeoff); +PROTO_STD_DEPRECATED(timespec_get); PROTO_NORMAL(tzset); PROTO_DEPRECATED(tzsetwall); diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index a919c39c5a4..8e772f307cf 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ major=92 -minor=5 +minor=6 # note: If changes were made to include/thread_private.h or if system # calls were added/changed then librthread/shlib_version also be updated. |