summaryrefslogtreecommitdiff
path: root/lib/strftime.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2015-10-25 10:49:41 +0000
committerAndy Wingo <wingo@pobox.com>2015-10-25 10:55:14 +0000
commit95ac2204d9084a01677fff9eb2669c495bd07d3d (patch)
treeb603eaaf67caaab75489478ab51605a70be006fa /lib/strftime.c
parent1c9e23c0901363ff24c1dc4e085e7ed68cb81e6d (diff)
downloadguile-95ac2204d9084a01677fff9eb2669c495bd07d3d.tar.gz
Revert "Update Gnulib to v0.1-603-g1d16a7b"
This reverts commit 2d4da30fdefbcdb065d4b1f48f2a77d06f69e3c3. This Gnulib update was causing failures related to timezones in stime.c. I tried to fix it by adopting the time_rz module from gnulib but that then caused other failures. We can try again later.
Diffstat (limited to 'lib/strftime.c')
-rw-r--r--lib/strftime.c122
1 files changed, 62 insertions, 60 deletions
diff --git a/lib/strftime.c b/lib/strftime.c
index 876d16e2b..eb458d117 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2001, 2003-2007, 2009-2015 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2001, 2003-2007, 2009-2014 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
@@ -30,7 +30,6 @@
# else
# include "strftime.h"
# endif
-# include "time-internal.h"
#endif
#include <ctype.h>
@@ -122,11 +121,22 @@ extern char *tzname[];
#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
@@ -375,7 +385,12 @@ iso_week_days (int yday, int wday)
/* When compiling this file, GNU applications can #define my_strftime
to a symbol (typically nstrftime) to get an extended strftime with
- extra arguments TZ and NS. */
+ 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
#if FPRINTFTIME
# undef my_strftime
@@ -383,9 +398,8 @@ iso_week_days (int yday, int wday)
#endif
#ifdef my_strftime
-# undef HAVE_TZSET
-# define extra_args , tz, ns
-# define extra_args_spec , timezone_t tz, int ns
+# define extra_args , ut, ns
+# define extra_args_spec , int ut, int ns
#else
# if defined COMPILE_WIDE
# define my_strftime wcsftime
@@ -397,7 +411,7 @@ iso_week_days (int yday, int wday)
# define extra_args
# define extra_args_spec
/* We don't have this information in general. */
-# define tz 1
+# define ut 0
# define ns 0
#endif
@@ -441,9 +455,6 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
# define am_len STRLEN (a_month)
# define ap_len STRLEN (ampm)
#endif
-#if HAVE_TZNAME
- char **tzname_vec = tzname;
-#endif
const char *zone;
size_t i = 0;
STREAM_OR_CHAR_T *p = s;
@@ -472,29 +483,20 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
zone = (const char *) tp->tm_zone;
#endif
#if HAVE_TZNAME
- if (!tz)
+ if (ut)
{
if (! (zone && *zone))
zone = "GMT";
}
else
{
-# if !HAVE_TM_ZONE
- /* Infer the zone name from *TZ instead of from TZNAME. */
- tzname_vec = tz->tzname_copy;
-# endif
/* POSIX.1 requires that local time zone information be used as
though strftime called tzset. */
# if HAVE_TZSET
tzset ();
# endif
}
- /* The tzset() call might have changed the value. */
- if (!(zone && *zone) && tp->tm_isdst >= 0)
- zone = tzname_vec[tp->tm_isdst != 0];
#endif
- if (! zone)
- zone = "";
if (hour12 > 12)
hour12 -= 12;
@@ -679,44 +681,24 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
switch (format_char)
{
#define DO_NUMBER(d, v) \
- do \
- { \
- digits = d; \
- number_value = v; \
- goto do_number; \
- } \
- while (0)
+ digits = d; \
+ number_value = v; goto do_number
#define DO_SIGNED_NUMBER(d, negative, v) \
- do \
- { \
- digits = d; \
- negative_number = negative; \
- u_number_value = v; \
- goto do_signed_number; \
- } \
- while (0)
+ digits = d; \
+ negative_number = negative; \
+ u_number_value = v; goto do_signed_number
/* The mask is not what you might think.
When the ordinal i'th bit is set, insert a colon
before the i'th digit of the time zone representation. */
#define DO_TZ_OFFSET(d, negative, mask, v) \
- do \
- { \
- digits = d; \
- negative_number = negative; \
- tz_colon_mask = mask; \
- u_number_value = v; \
- goto do_tz_offset; \
- } \
- while (0)
+ digits = d; \
+ negative_number = negative; \
+ tz_colon_mask = mask; \
+ u_number_value = v; goto do_tz_offset
#define DO_NUMBER_SPACEPAD(d, v) \
- do \
- { \
- digits = d; \
- number_value = v; \
- goto do_number_spacepad; \
- } \
- while (0)
+ digits = d; \
+ number_value = v; goto do_number_spacepad
case L_('%'):
if (modifier != 0)
@@ -1142,7 +1124,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
time_t t;
ltm = *tp;
- t = mktime_z (tz, &ltm);
+ t = mktime (&ltm);
/* Generate string value for T using time_t arithmetic;
this works even if sizeof (long) < sizeof (time_t). */
@@ -1283,9 +1265,9 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
}
if (modifier == L_('O'))
goto bad_format;
-
- DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE,
- tp->tm_year + (unsigned int) TM_YEAR_BASE);
+ else
+ DO_SIGNED_NUMBER (4, tp->tm_year < -TM_YEAR_BASE,
+ tp->tm_year + (unsigned int) TM_YEAR_BASE);
case L_('y'):
if (modifier == L_('E'))
@@ -1317,6 +1299,14 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
to_lowcase = true;
}
+#if HAVE_TZNAME
+ /* The tzset() call might have changed the value. */
+ if (!(zone && *zone) && tp->tm_isdst >= 0)
+ zone = tzname[tp->tm_isdst != 0];
+#endif
+ if (! zone)
+ zone = "";
+
#ifdef COMPILE_WIDE
{
/* The zone string is always given in multibyte form. We have
@@ -1356,7 +1346,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
#if HAVE_TM_GMTOFF
diff = tp->tm_gmtoff;
#else
- if (!tz)
+ if (ut)
diff = 0;
else
{
@@ -1365,7 +1355,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
time_t lt;
ltm = *tp;
- lt = mktime_z (tz, &ltm);
+ lt = mktime (&ltm);
if (lt == (time_t) -1)
{
@@ -1374,7 +1364,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
occurred. */
struct tm tm;
- if (! localtime_rz (tz, &lt, &tm)
+ if (! __localtime_r (&lt, &tm)
|| ((ltm.tm_sec ^ tm.tm_sec)
| (ltm.tm_min ^ tm.tm_min)
| (ltm.tm_hour ^ tm.tm_hour)
@@ -1384,7 +1374,7 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
break;
}
- if (! localtime_rz (0, &lt, &gtm))
+ if (! __gmtime_r (&lt, &gtm))
break;
diff = tm_diff (&ltm, &gtm);
@@ -1463,3 +1453,15 @@ my_strftime (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
#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