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 /lib/libc/gen | |
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@
Diffstat (limited to 'lib/libc/gen')
-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 |
3 files changed, 136 insertions, 3 deletions
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; +} |