From 2d4f9d5c5a0c6dbdc2fbe34c42fe9cd74f162af3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 2 Jan 2021 00:14:05 +0100 Subject: [PATCH 1/3] 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. --- ChangeLog | 10 ++++++++++ doc/posix-headers/time.texi | 6 ++++-- lib/time.in.h | 8 ++++++++ m4/time_h.m4 | 18 +++++++++++++++++- modules/time | 1 + tests/test-time.c | 4 ++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16fafe4..f222500 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2021-01-01 Bruno Haible + 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 + stddef: Try harder to get max_align_t defined on OpenBSD, part 2. * modules/stddef (Depends-on): Add extensions. diff --git a/doc/posix-headers/time.texi b/doc/posix-headers/time.texi index 980212c..9d25ed2 100644 --- a/doc/posix-headers/time.texi +++ b/doc/posix-headers/time.texi @@ -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: diff --git a/lib/time.in.h b/lib/time.in.h index 9ed57e4..33c4dad 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -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 . */ diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 07e6967..439ee74 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 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 ], + [gl_cv_time_h_has_TIME_UTC], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[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 diff --git a/modules/time b/modules/time index 2f91fa3..2932375 100644 --- a/modules/time +++ b/modules/time @@ -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)' \ diff --git a/tests/test-time.c b/tests/test-time.c index a3a3276..e5a4522 100644 --- a/tests/test-time.c +++ b/tests/test-time.c @@ -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) { -- 2.7.4