]> Savannah Git Hosting - gnulib.git/commitdiff
tzname: New module.
authorBruno Haible <bruno@clisp.org>
Thu, 6 Jun 2024 15:47:21 +0000 (17:47 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 6 Jun 2024 16:02:53 +0000 (18:02 +0200)
* lib/time.in.h (tzname): New declaration.
* m4/tzname.m4: New file.
* m4/time_h.m4 (gl_TIME_H_REQUIRE_DEFAULTS): Initialize GNULIB_TZNAME.
* modules/time-h (Makefile.am): Substitute GNULIB_TZNAME.
* modules/tzname: New file.
* doc/posix-functions/tzname.texi: Mention the new module.

ChangeLog
doc/posix-functions/tzname.texi
lib/time.in.h
m4/time_h.m4
m4/tzname.m4 [new file with mode: 0644]
modules/time-h
modules/tzname [new file with mode: 0644]

index f5d56af5d5b8fd2f3fc1bba6825b6f4e03695534..97733e4c405b955a10d5fca94d00c45121afc14f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-06-06  Bruno Haible  <bruno@clisp.org>
+
+       tzname: New module.
+       * lib/time.in.h (tzname): New declaration.
+       * m4/tzname.m4: New file.
+       * m4/time_h.m4 (gl_TIME_H_REQUIRE_DEFAULTS): Initialize GNULIB_TZNAME.
+       * modules/time-h (Makefile.am): Substitute GNULIB_TZNAME.
+       * modules/tzname: New file.
+       * doc/posix-functions/tzname.texi: Mention the new module.
+
 2024-06-06  Bruno Haible  <bruno@clisp.org>
 
        tzname, daylight, timezone: Update documentation.
index d56ff5c924a41877eb4e71b4304b41761a1459dc..e3413d47deae9d45d8e28cd51371c1099afad36a 100644 (file)
@@ -4,18 +4,18 @@
 
 POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/tzname.html}
 
-Gnulib module: ---
+Gnulib module: tzname
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This variable is called @code{_tzname} on some platforms:
+mingw with @code{-DNO_OLDNAMES}, MSVC.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This variable is called @code{_tzname} on some platforms:
-mingw with @code{-DNO_OLDNAMES}, MSVC.
-@item
 The address of this variable is not a compile-time constant on some platforms:
 Cygwin, mingw, MSVC.
 @item
index df99c8abca9b932e8427e1c37e931e563cb885f0..b91018937adc236ebac74905dcd35a8b31199ce0 100644 (file)
@@ -122,6 +122,23 @@ struct __time_t_must_be_integral {
 #  endif
 # endif
 
+# if @GNULIB_TZNAME@
+/* tzname[0..1]: Abbreviated time zone names, set by the tzset() function.  */
+#  if NEED_DECL_TZNAME
+extern
+#   ifdef __cplusplus
+  "C"
+#   endif
+  char *tzname[];
+#  endif
+#  if defined _WIN32 && !defined __CYGWIN__
+/* On native Windows, map 'tzname' to '_tzname' etc., so that -loldnames is not
+   required.  */
+#   undef tzname
+#   define tzname _tzname
+#  endif
+# endif
+
 /* Set *TS to the current time, and return BASE.
    Upon failure, return 0.  */
 # if @GNULIB_TIMESPEC_GET@
index d2f3c9701cbd4ca0a501bc39548bc478ca9065d8..4ca7305792c370f30afd4e20ae000378c5e52acc 100644 (file)
@@ -1,5 +1,5 @@
 # time_h.m4
-# serial 25
+# serial 26
 dnl Copyright (C) 2000-2001, 2003-2007, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -145,6 +145,7 @@ AC_DEFUN([gl_TIME_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIMESPEC_GETRES])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_R])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TIME_RZ])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZNAME])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TZSET])
     dnl Support Microsoft deprecated alias function names by default.
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_TZSET], [1])
diff --git a/m4/tzname.m4 b/m4/tzname.m4
new file mode 100644 (file)
index 0000000..b600e56
--- /dev/null
@@ -0,0 +1,62 @@
+# tzname.m4
+# serial 1
+dnl Copyright (C) 2024 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.
+
+dnl gl_TZNAME tests how the time zone can be obtained.
+dnl It is similar AC_STRUCT_TIMEZONE, but also supports MSVC.
+dnl It defines
+dnl   * the C macro HAVE_STRUCT_TM_TM_ZONE to 1 if 'struct tm' has a field
+dnl     'tm_zone',
+dnl   * otherwise:
+dnl     - the C macro HAVE_TZNAME_ARRAY to 1 if there the rvalue 'tzname'
+dnl       or (on native Windows) '_tzname' is usable,
+dnl     - the C macro NEED_DECL_TZNAME to 1 if 'tzname' needs to be declared
+dnl         extern char *tzname[];
+dnl       before use.
+AC_DEFUN([gl_TZNAME],
+[
+  AC_REQUIRE([AC_CANONICAL_HOST])
+
+  dnl Set ac_cv_member_struct_tm_tm_zone,
+  dnl     ac_cv_var_tzname, ac_cv_have_decl_tzname.
+  dnl Possibly define HAVE_STRUCT_TM_TM_ZONE,
+  dnl                 HAVE_TZNAME, HAVE_DECL_TZNAME.
+  AC_REQUIRE([AC_STRUCT_TIMEZONE])
+
+  dnl If 'struct tm' has a field 'tm_zone', don't test for tzname or _tzname.
+  dnl Rationale: Some code assumes that HAVE_STRUCT_TM_TM_ZONE and HAVE_TZNAME
+  dnl are exclusive.
+  if test "$ac_cv_member_struct_tm_tm_zone" != yes; then
+    if test $ac_cv_var_tzname = yes && test $ac_cv_have_decl_tzname != yes; then
+      AC_DEFINE([NEED_DECL_TZNAME], [1],
+        [Define to 1 if tzname exists but needs to be declared.])
+    fi
+    AC_CACHE_CHECK([for tzname array],
+      [gl_cv_var_tzname],
+      [AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <time.h>
+              #if NEED_DECL_TZNAME
+              extern char *tzname[];
+              #endif
+              #if defined _WIN32 && !defined __CYGWIN__
+               #undef tzname
+               #define tzname _tzname
+              #endif
+            ]],
+            [[return tzname[0][0];
+            ]])
+         ],
+         [gl_cv_var_tzname=yes],
+         [gl_cv_var_tzname=no])
+      ])
+    if test $gl_cv_var_tzname = yes; then
+      AC_DEFINE([HAVE_TZNAME_ARRAY], [1],
+                [Define to 1 if 'struct tm' does not have a field 'tm_zone'
+                 but instead 'tzname' is usable.])
+    fi
+  fi
+])
index 3b07845b56614918d8a1ef256618109fbd0011cb..e84100bf93375eef8e8e95d81aede57fef22614f 100644 (file)
@@ -44,6 +44,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_TIMESPEC_GETRES''@/$(GNULIB_TIMESPEC_GETRES)/g' \
              -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
              -e 's/@''GNULIB_TIME_RZ''@/$(GNULIB_TIME_RZ)/g' \
+             -e 's/@''GNULIB_TZNAME''@/$(GNULIB_TZNAME)/g' \
              -e 's/@''GNULIB_TZSET''@/$(GNULIB_TZSET)/g' \
              -e 's/@''GNULIB_MDA_TZSET''@/$(GNULIB_MDA_TZSET)/g' \
              -e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
diff --git a/modules/tzname b/modules/tzname
new file mode 100644 (file)
index 0000000..4195d74
--- /dev/null
@@ -0,0 +1,23 @@
+Description:
+tzname variable: abbreviated time zone names, set by the tzset() function.
+
+Files:
+m4/tzname.m4
+
+Depends-on:
+time-h
+
+configure.ac:
+gl_TZNAME
+gl_TIME_MODULE_INDICATOR([tzname])
+
+Makefile.am:
+
+Include:
+<time.h>
+
+License:
+LGPL
+
+Maintainer:
+all