* 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-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.
@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
# 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>. */
--- /dev/null
+/* 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;
+}
# 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,
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])
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.
--- /dev/null
+# 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
+])
-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' \
-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' \
--- /dev/null
+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
#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 *));