From owner-svn-src-all@freebsd.org Fri Aug 10 15:16:33 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D6024106DB46; Fri, 10 Aug 2018 15:16:32 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 88C348F100; Fri, 10 Aug 2018 15:16:32 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5EFBD1D6D; Fri, 10 Aug 2018 15:16:32 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7AFGWOD037304; Fri, 10 Aug 2018 15:16:32 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7AFGV3n037298; Fri, 10 Aug 2018 15:16:31 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201808101516.w7AFGV3n037298@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 10 Aug 2018 15:16:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337576 - in head: include lib/libc/gen sys/sys X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head: include lib/libc/gen sys/sys X-SVN-Commit-Revision: 337576 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Aug 2018 15:16:33 -0000 Author: imp Date: Fri Aug 10 15:16:30 2018 New Revision: 337576 URL: https://svnweb.freebsd.org/changeset/base/337576 Log: 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 Added: head/lib/libc/gen/timespec_get.3 (contents, props changed) head/lib/libc/gen/timespec_get.c (contents, props changed) Modified: head/include/time.h head/lib/libc/gen/Makefile.inc head/lib/libc/gen/Symbol.map head/sys/sys/param.h Modified: head/include/time.h ============================================================================== --- head/include/time.h Fri Aug 10 14:47:16 2018 (r337575) +++ head/include/time.h Fri Aug 10 15:16:30 2018 (r337576) @@ -206,6 +206,11 @@ time_t posix2time(time_t t); #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_) #include #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_ */ Modified: head/lib/libc/gen/Makefile.inc ============================================================================== --- head/lib/libc/gen/Makefile.inc Fri Aug 10 14:47:16 2018 (r337575) +++ head/lib/libc/gen/Makefile.inc Fri Aug 10 15:16:30 2018 (r337576) @@ -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 \ Modified: head/lib/libc/gen/Symbol.map ============================================================================== --- head/lib/libc/gen/Symbol.map Fri Aug 10 14:47:16 2018 (r337575) +++ head/lib/libc/gen/Symbol.map Fri Aug 10 15:16:30 2018 (r337576) @@ -420,6 +420,7 @@ FBSD_1.5 { scandir_b; sem_clockwait_np; setproctitle_fast; + timespec_get; }; FBSDprivate_1.0 { Added: head/lib/libc/gen/timespec_get.3 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/gen/timespec_get.3 Fri Aug 10 15:16:30 2018 (r337576) @@ -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 Added: head/lib/libc/gen/timespec_get.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/gen/timespec_get.c Fri Aug 10 15:16:30 2018 (r337576) @@ -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 +__RCSID("$NetBSD: timespec_get.c,v 1.2 2016/10/04 12:48:15 christos Exp $"); +__FBSDID("$FreeBSD$"); + +#include +#include + +/* 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; +} Modified: head/sys/sys/param.h ============================================================================== --- head/sys/sys/param.h Fri Aug 10 14:47:16 2018 (r337575) +++ head/sys/sys/param.h Fri Aug 10 15:16:30 2018 (r337576) @@ -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,