]> Savannah Git Hosting - gnulib.git/commitdiff
timespec_get: New module.
authorBruno Haible <bruno@clisp.org>
Sat, 2 Jan 2021 12:14:08 +0000 (13:14 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 2 Jan 2021 12:14:08 +0000 (13:14 +0100)
* 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.

ChangeLog
doc/glibc-functions/timespec_get.texi
lib/time.in.h
lib/timespec_get.c [new file with mode: 0644]
m4/time_h.m4
m4/timespec_get.m4 [new file with mode: 0644]
modules/time
modules/timespec_get [new file with mode: 0644]
tests/test-time-c++.cc

index f222500534950e22e228b42d206c0c448530ff8c..899f7a13d6e0c720fc68d034f93062c88963a658 100644 (file)
--- 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.
index 8113a9be9d6e1df1f875c63c3c1c29707fda1dee..c5cf236a3073d7c64dff0269807dbe29a8da0373 100644 (file)
@@ -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
index 33c4dadf603b7234bf46404ddf2f55849238399f..4da1172bded1b0bb74f32aaf2f7320f62c365b03 100644 (file)
@@ -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 (file)
index 0000000..d738c12
--- /dev/null
@@ -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;
+}
index 439ee74fb036a5fe34e2c4a1e3aee5ec8c85c70d..b6a1aa3bc0f07e6ec9b5de21ec0c0fdbcb5902be 100644 (file)
@@ -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 (file)
index 0000000..a4a3b78
--- /dev/null
@@ -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
+])
index 2932375e57b136e959185805bab8c66201f534a4..c0fb27dc4c9fc9f357c7122c56ca811449698b40 100644 (file)
@@ -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 (file)
index 0000000..51efed3
--- /dev/null
@@ -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
index 07fff990574931c3327c767f98381da859b5d5a4..cdcd61e81f5b142fbb7495f050802b8bd47cdff9 100644 (file)
 #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 *));