Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Aug 2018 15:16:31 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
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
Message-ID:  <201808101516.w7AFGV3n037298@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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_ */

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 <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;
+}

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,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201808101516.w7AFGV3n037298>