changeset 18060:ea0b31e02258

fprintftime, strftime: use timezone_t args * NEWS: Document the change. * lib/fprintftime.h (fprintftime): * lib/strftime.c (extra_args) [my_strftime]: * lib/strftime.h (nstrftime): Time zone arg is now of type timezone_t, not int. * lib/strftime.c (mktime_z) [_LIBC]: New macro. (__gmtime_r, __localtime_r) [!HAVE_TM_GMTOFF]: Remove; no longer used. (my_strftime) [emacs && !my_strftime]: (emacs_strftimeu) [emacs && !FPRINTFTIME]: Remove; Emacs doesn't need this any more. (HAVE_TZSET) [my_strftime]: Unset, since we no longer want fprintftime and nstrftime to call tzset. (ut) [!my_strftime]: Remove, replacing with ... (tz) [!my_stftime]: ... this new macro. All uses changed. (strftime_case_): Use localtime_rz and mktime_z instead of localtime_r and mktime. * modules/fprintftime (Depends-on): Add time_rz. * modules/strftime (Depends-on): Add time_rz. Remove time_r. * tests/test-strftime.c (main): Adjust to new nstrftime API.
author Paul Eggert <eggert@cs.ucla.edu>
date Thu, 23 Jul 2015 18:28:13 -0700
parents 20ad7d4822c8
children af90c3b0922f
files ChangeLog NEWS lib/fprintftime.h lib/strftime.c lib/strftime.h modules/fprintftime modules/strftime tests/test-strftime.c
diffstat 8 files changed, 46 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2015-07-23  Paul Eggert  <eggert@cs.ucla.edu>
 
+	fprintftime, strftime: use timezone_t args
+	* NEWS: Document the change.
+	* lib/fprintftime.h (fprintftime):
+	* lib/strftime.c (extra_args) [my_strftime]:
+	* lib/strftime.h (nstrftime):
+	Time zone arg is now of type timezone_t, not int.
+	* lib/strftime.c (mktime_z) [_LIBC]: New macro.
+	(__gmtime_r, __localtime_r) [!HAVE_TM_GMTOFF]: Remove; no longer used.
+	(my_strftime) [emacs && !my_strftime]:
+	(emacs_strftimeu) [emacs && !FPRINTFTIME]:
+	Remove; Emacs doesn't need this any more.
+	(HAVE_TZSET) [my_strftime]: Unset, since we no longer want
+	fprintftime and nstrftime to call tzset.
+	(ut) [!my_strftime]: Remove, replacing with ...
+	(tz) [!my_stftime]: ... this new macro.  All uses changed.
+	(strftime_case_): Use localtime_rz and mktime_z instead
+	of localtime_r and mktime.
+	* modules/fprintftime (Depends-on): Add time_rz.
+	* modules/strftime (Depends-on): Add time_rz.  Remove time_r.
+	* tests/test-strftime.c (main): Adjust to new nstrftime API.
+
 	time_rz: new module
 	* MODULES.html.sh: Add time_rz.
 	* lib/time_rz.c, m4/time_rz.m4, modules/time_rz: New files.
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,11 @@
 
 Date        Modules         Changes
 
+2015-07-24  fprintftime     Exported functions' time zone arguments are now of
+            strftime        type timezone_t (with NULL denoting UTC) instead of
+                            type int (with nonzero denoting UTC).  These
+                            modules now depend on time_rz.
+
 2015-04-03  hash            hash_insert0 function removed (deprecated in 2011).
 
 2014-10-29  obstack         The obstack functions are no longer limited to
--- a/lib/fprintftime.h
+++ b/lib/fprintftime.h
@@ -23,7 +23,7 @@
    large buffer that nstrftime would require.
 
    Output to stream FP the result of formatting (according to the
-   nstrftime format string, FMT) the time data, *TM, and the UTC
+   nstrftime format string, FMT) the time data, *TM, and the ZONE
    and NANOSECONDS values.  */
 size_t fprintftime (FILE *fp, char const *fmt, struct tm const *tm,
-                    int utc, int nanoseconds);
+                    timezone_t zone, int nanoseconds);
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -121,22 +121,11 @@
 
 
 #ifdef _LIBC
+# define mktime_z(tz, tm) mktime (tm)
 # define tzname __tzname
 # define tzset __tzset
 #endif
 
-#if !HAVE_TM_GMTOFF
-/* Portable standalone applications should supply a "time.h" that
-   declares a POSIX-compliant localtime_r, for the benefit of older
-   implementations that lack localtime_r or have a nonstandard one.
-   See the gnulib time_r module for one way to implement this.  */
-# undef __gmtime_r
-# undef __localtime_r
-# define __gmtime_r gmtime_r
-# define __localtime_r localtime_r
-#endif
-
-
 #ifndef FPRINTFTIME
 # define FPRINTFTIME 0
 #endif
@@ -385,12 +374,7 @@
 
 /* When compiling this file, GNU applications can #define my_strftime
    to a symbol (typically nstrftime) to get an extended strftime with
-   extra arguments UT and NS.  Emacs is a special case for now, but
-   this Emacs-specific code can be removed once Emacs's config.h
-   defines my_strftime.  */
-#if defined emacs && !defined my_strftime
-# define my_strftime nstrftime
-#endif
+   extra arguments TZ and NS.  */
 
 #if FPRINTFTIME
 # undef my_strftime
@@ -398,8 +382,9 @@
 #endif
 
 #ifdef my_strftime
-# define extra_args , ut, ns
-# define extra_args_spec , int ut, int ns
+# undef HAVE_TZSET
+# define extra_args , tz, ns
+# define extra_args_spec , timezone_t tz, int ns
 #else
 # if defined COMPILE_WIDE
 #  define my_strftime wcsftime
@@ -411,7 +396,7 @@
 # define extra_args
 # define extra_args_spec
 /* We don't have this information in general.  */
-# define ut 0
+# define tz 1
 # define ns 0
 #endif
 
@@ -483,7 +468,7 @@
   zone = (const char *) tp->tm_zone;
 #endif
 #if HAVE_TZNAME
-  if (ut)
+  if (!tz)
     {
       if (! (zone && *zone))
         zone = "GMT";
@@ -1144,7 +1129,7 @@
             time_t t;
 
             ltm = *tp;
-            t = mktime (&ltm);
+            t = mktime_z (tz, &ltm);
 
             /* Generate string value for T using time_t arithmetic;
                this works even if sizeof (long) < sizeof (time_t).  */
@@ -1366,7 +1351,7 @@
 #if HAVE_TM_GMTOFF
             diff = tp->tm_gmtoff;
 #else
-            if (ut)
+            if (!tz)
               diff = 0;
             else
               {
@@ -1375,7 +1360,7 @@
                 time_t lt;
 
                 ltm = *tp;
-                lt = mktime (&ltm);
+                lt = mktime_z (tz, &ltm);
 
                 if (lt == (time_t) -1)
                   {
@@ -1384,7 +1369,7 @@
                        occurred.  */
                     struct tm tm;
 
-                    if (! __localtime_r (&lt, &tm)
+                    if (! localtime_rz (tz, &lt, &tm)
                         || ((ltm.tm_sec ^ tm.tm_sec)
                             | (ltm.tm_min ^ tm.tm_min)
                             | (ltm.tm_hour ^ tm.tm_hour)
@@ -1394,7 +1379,7 @@
                       break;
                   }
 
-                if (! __gmtime_r (&lt, &gtm))
+                if (! localtime_rz (0, &lt, &gtm))
                   break;
 
                 diff = tm_diff (&ltm, &gtm);
@@ -1473,15 +1458,3 @@
 #if defined _LIBC && ! FPRINTFTIME
 libc_hidden_def (my_strftime)
 #endif
-
-
-#if defined emacs && ! FPRINTFTIME
-/* For Emacs we have a separate interface which corresponds to the normal
-   strftime function plus the ut argument, but without the ns argument.  */
-size_t
-emacs_strftimeu (char *s, size_t maxsize, const char *format,
-                 const struct tm *tp, int ut)
-{
-  return my_strftime (s, maxsize, format, tp, ut, 0);
-}
-#endif
--- a/lib/strftime.h
+++ b/lib/strftime.h
@@ -23,11 +23,10 @@
 
 /* Just like strftime, but with two more arguments:
    POSIX requires that strftime use the local timezone information.
-   When __UTC is nonzero and tm->tm_zone is NULL or the empty string,
-   use UTC instead.  Use __NS as the number of nanoseconds in the
-   %N directive.  */
+   Use the timezone __TZ instead.  Use __NS as the number of
+   nanoseconds in the %N directive.  */
 size_t nstrftime (char *, size_t, char const *, struct tm const *,
-                  int __utc, int __ns);
+                  timezone_t __tz, int __ns);
 
 #ifdef __cplusplus
 }
--- a/modules/fprintftime
+++ b/modules/fprintftime
@@ -8,6 +8,7 @@
 Depends-on:
 stdio
 strftime
+time_rz
 
 configure.ac:
 
--- a/modules/strftime
+++ b/modules/strftime
@@ -10,7 +10,7 @@
 Depends-on:
 extensions
 stdbool
-time_r
+time_rz
 
 configure.ac:
 gl_FUNC_GNU_STRFTIME
--- a/tests/test-strftime.c
+++ b/tests/test-strftime.c
@@ -54,11 +54,10 @@
       time_t t = T[i].in;
       struct tm *tm = gmtime (&t);
       size_t n;
-      int utc = 1;
 
       ASSERT (tm);
 
-      n = nstrftime (buf, sizeof buf, T[i].fmt, tm, utc, T[i].in_ns);
+      n = nstrftime (buf, sizeof buf, T[i].fmt, tm, 0, T[i].in_ns);
       if (n == 0)
         {
           fail = 1;