]> Savannah Git Hosting - gnulib.git/commitdiff
time: Define TIME_UTC.
authorBruno Haible <bruno@clisp.org>
Fri, 1 Jan 2021 23:14:05 +0000 (00:14 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 2 Jan 2021 00:15:46 +0000 (01:15 +0100)
* lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros.
* m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC.
* modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC.
* tests/test-time.c: Check that TIME_UTC is defined and a positive
integer.
* doc/posix-headers/time.texi: Mention TIME_UTC.

ChangeLog
doc/posix-headers/time.texi
lib/time.in.h
m4/time_h.m4
modules/time
tests/test-time.c

index 16fafe4d0b2a216ecd5d121b8845c4b53277a1bd..f222500534950e22e228b42d206c0c448530ff8c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2021-01-01  Bruno Haible  <bruno@clisp.org>
+
+       time: Define TIME_UTC.
+       * lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros.
+       * m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC.
+       * modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC.
+       * tests/test-time.c: Check that TIME_UTC is defined and a positive
+       integer.
+       * doc/posix-headers/time.texi: Mention TIME_UTC.
+
 2021-01-01  Bruno Haible  <bruno@clisp.org>
 
        stddef: Try harder to get max_align_t defined on OpenBSD, part 2.
index 980212cc58eb12baef74c5679ba7b5393f079bc9..9d25ed2508c512d1cf57c22a6057408e8190a8c9 100644 (file)
@@ -9,11 +9,13 @@ Portability problems fixed by Gnulib:
 @itemize
 @item
 @samp{struct timespec} is not defined on some platforms.
-
+@item
+The macro @code{TIME_UTC} is not defined 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.
 @item
 Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
 expressions:
-NetBSD 5.0
+NetBSD 5.0.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 9ed57e40d1a03ea09bf24a85688842e24f36858c..33c4dadf603b7234bf46404ddf2f55849238399f 100644 (file)
@@ -101,6 +101,14 @@ struct __time_t_must_be_integral {
 #  define GNULIB_defined_struct_time_t_must_be_integral 1
 # endif
 
+/* Define TIME_UTC, a positive integer constant used for timespec_get().  */
+# if ! @TIME_H_DEFINES_TIME_UTC@
+#  if !GNULIB_defined_TIME_UTC
+#   define TIME_UTC 1
+#   define GNULIB_defined_TIME_UTC 1
+#  endif
+# 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>.  */
index 07e6967e45b396f7a7d8b066242d063285b3de16..439ee74fb036a5fe34e2c4a1e3aee5ec8c85c70d 100644 (file)
@@ -2,7 +2,7 @@
 
 # Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc.
 
-# serial 13
+# serial 14
 
 # This file is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -25,6 +25,22 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY],
   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
 
   AC_REQUIRE([AC_C_RESTRICT])
+
+  AC_CACHE_CHECK([for TIME_UTC in <time.h>],
+    [gl_cv_time_h_has_TIME_UTC],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[#include <time.h>
+          ]],
+          [[static int x = TIME_UTC; x++;]])],
+       [gl_cv_time_h_has_TIME_UTC=yes],
+       [gl_cv_time_h_has_TIME_UTC=no])])
+  if test $gl_cv_time_h_has_TIME_UTC = yes; then
+    TIME_H_DEFINES_TIME_UTC=1
+  else
+    TIME_H_DEFINES_TIME_UTC=0
+  fi
+  AC_SUBST([TIME_H_DEFINES_TIME_UTC])
 ])
 
 dnl Check whether 'struct timespec' is declared
index 2f91fa3e7f3b28cf83b093f2ef8286767fbfe595..2932375e57b136e959185805bab8c66201f534a4 100644 (file)
@@ -58,6 +58,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
              -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
              -e 's|@''UNISTD_H_DEFINES_STRUCT_TIMESPEC''@|$(UNISTD_H_DEFINES_STRUCT_TIMESPEC)|g' \
+             -e 's|@''TIME_H_DEFINES_TIME_UTC''@|$(TIME_H_DEFINES_TIME_UTC)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
index a3a327624ec6e3ea080a529b9eca5f3904018e04..e5a45227b7aef05042dd8745da9fc269b6f60a49 100644 (file)
@@ -34,6 +34,10 @@ pid_t t2;
    per POSIX 2008.  */
 verify (sizeof NULL == sizeof (void *));
 
+/* Check that TIME_UTC is defined and a positive integer.  */
+int t3 = TIME_UTC;
+verify (TIME_UTC > 0);
+
 int
 main (void)
 {