summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--doc/glibc-functions/timespec_get.texi8
-rw-r--r--lib/time.in.h11
-rw-r--r--lib/timespec_get.c33
-rw-r--r--m4/time_h.m44
-rw-r--r--m4/timespec_get.m418
-rw-r--r--modules/time2
-rw-r--r--modules/timespec_get32
-rw-r--r--tests/test-time-c++.cc4
9 files changed, 121 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index f222500534..899f7a13d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2021-01-02 Bruno Haible <bruno@clisp.org>
+
+ timespec_get: New module.
+ * lib/time.in.h (timespec_get): New declaration.
+ * lib/timespec_get.c: New file.
+ * m4/timespec_get.m4: New file.
+ * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize
+ GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET.
+ * modules/time (Makefile.am): Substitute GNULIB_TIMESPEC_GET,
+ HAVE_TIMESPEC_GET.
+ * modules/timespec_get: New file.
+ * tests/test-time-c++.cc (timespec_get): Check signature.
+ * doc/glibc-functions/timespec_get.texi: Mention the new module.
+
2021-01-01 Bruno Haible <bruno@clisp.org>
time: Define TIME_UTC.
diff --git a/doc/glibc-functions/timespec_get.texi b/doc/glibc-functions/timespec_get.texi
index 8113a9be9d..c5cf236a30 100644
--- a/doc/glibc-functions/timespec_get.texi
+++ b/doc/glibc-functions/timespec_get.texi
@@ -2,15 +2,15 @@
@subsection @code{timespec_get}
@findex timespec_get
-Gnulib module: ---
+Gnulib module: timespec_get
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on many platforms:
+glibc 2.15, Mac OS X 10.13, FreeBSD 6.4, NetBSD 7.1, OpenBSD 6.0, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on many platforms:
-glibc 2.15, Mac OS X 10.13, FreeBSD 6.4, NetBSD 7.1, OpenBSD 6.0, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0.
@end itemize
diff --git a/lib/time.in.h b/lib/time.in.h
index 33c4dadf60..4da1172bde 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -109,6 +109,17 @@ struct __time_t_must_be_integral {
# endif
# endif
+/* Set *TS to the current time, and return BASE.
+ Upon failure, return 0. */
+# if @GNULIB_TIMESPEC_GET@
+# if ! @HAVE_TIMESPEC_GET@
+_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base)
+ _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base));
+_GL_CXXALIASWARN (timespec_get);
+# endif
+
/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
return -1 and store the remaining time into RMTP. See
<https://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html>. */
diff --git a/lib/timespec_get.c b/lib/timespec_get.c
new file mode 100644
index 0000000000..d738c12b89
--- /dev/null
+++ b/lib/timespec_get.c
@@ -0,0 +1,33 @@
+/* timespec_get() function.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <time.h>
+
+#include "timespec.h"
+
+int
+timespec_get (struct timespec *ts, int base)
+{
+ if (base == TIME_UTC)
+ {
+ gettime (ts);
+ return base;
+ }
+ return 0;
+}
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index 439ee74fb0..b6a1aa3bc0 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -2,7 +2,7 @@
# Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc.
-# serial 14
+# serial 15
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -129,6 +129,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
GNULIB_STRFTIME=0; AC_SUBST([GNULIB_STRFTIME])
GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
+ GNULIB_TIMESPEC_GET=0; AC_SUBST([GNULIB_TIMESPEC_GET])
GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
GNULIB_TIME_RZ=0; AC_SUBST([GNULIB_TIME_RZ])
GNULIB_TZSET=0; AC_SUBST([GNULIB_TZSET])
@@ -139,6 +140,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
+ HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET])
dnl Even GNU libc does not have timezone_t yet.
HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T])
dnl If another module says to replace or to not replace, do that.
diff --git a/m4/timespec_get.m4 b/m4/timespec_get.m4
new file mode 100644
index 0000000000..a4a3b78b81
--- /dev/null
+++ b/m4/timespec_get.m4
@@ -0,0 +1,18 @@
+# timespec_get.m4 serial 1
+dnl Copyright (C) 2021 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_TIMESPEC_GET],
+[
+ AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
+
+ dnl Persuade OpenBSD <time.h> to declare timespec_get().
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_FUNCS_ONCE([timespec_get])
+ if test $ac_cv_func_timespec_get != yes; then
+ HAVE_TIMESPEC_GET=0
+ fi
+])
diff --git a/modules/time b/modules/time
index 2932375e57..c0fb27dc4c 100644
--- a/modules/time
+++ b/modules/time
@@ -36,6 +36,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
-e 's/@''GNULIB_STRFTIME''@/$(GNULIB_STRFTIME)/g' \
-e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
-e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
+ -e 's/@''GNULIB_TIMESPEC_GET''@/$(GNULIB_TIMESPEC_GET)/g' \
-e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
-e 's/@''GNULIB_TIME_RZ''@/$(GNULIB_TIME_RZ)/g' \
-e 's/@''GNULIB_TZSET''@/$(GNULIB_TZSET)/g' \
@@ -44,6 +45,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
-e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
-e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
-e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
+ -e 's|@''HAVE_TIMESPEC_GET''@|$(HAVE_TIMESPEC_GET)|g' \
-e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
-e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
-e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
diff --git a/modules/timespec_get b/modules/timespec_get
new file mode 100644
index 0000000000..51efed3d7c
--- /dev/null
+++ b/modules/timespec_get
@@ -0,0 +1,32 @@
+Description:
+timespec_get() function: return the current time with up to nanosecond resolution
+
+Files:
+lib/timespec_get.c
+m4/timespec_get.m4
+
+Depends-on:
+time
+extensions
+gettime [test $HAVE_TIMESPEC_GET = 0]
+
+configure.ac:
+gl_FUNC_TIMESPEC_GET
+if test $HAVE_TIMESPEC_GET = 0; then
+ AC_LIBOBJ([timespec_get])
+fi
+gl_TIME_MODULE_INDICATOR([timespec_get])
+
+Makefile.am:
+
+Include:
+<time.h>
+
+Link:
+$(LIB_CLOCK_GETTIME)
+
+License:
+LGPL
+
+Maintainer:
+all
diff --git a/tests/test-time-c++.cc b/tests/test-time-c++.cc
index 07fff99057..cdcd61e81f 100644
--- a/tests/test-time-c++.cc
+++ b/tests/test-time-c++.cc
@@ -24,6 +24,10 @@
#include "signature.h"
+#if GNULIB_TEST_TIMESPEC_GET
+SIGNATURE_CHECK (GNULIB_NAMESPACE::timespec_get, int, (struct timespec *, int));
+#endif
+
#if GNULIB_TEST_NANOSLEEP
SIGNATURE_CHECK (GNULIB_NAMESPACE::nanosleep, int,
(struct timespec const *, struct timespec *));