summaryrefslogtreecommitdiff
path: root/libc/time
diff options
context:
space:
mode:
authorjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2007-10-18 16:47:43 +0000
committerjoseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d>2007-10-18 16:47:43 +0000
commit1014a34ffefed553055fbabd75bd1d3c6822763c (patch)
tree1490309748b0981835af5d565669d792364d647c /libc/time
parentaddc040a0abc7ec65344706c75bc07f7998942bb (diff)
Merge changes between r3809 and r3831 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@3852 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/time')
-rw-r--r--libc/time/strftime_l.c70
-rw-r--r--libc/time/tzfile.c13
2 files changed, 47 insertions, 36 deletions
diff --git a/libc/time/strftime_l.c b/libc/time/strftime_l.c
index 8e3c197e0..31e934e0b 100644
--- a/libc/time/strftime_l.c
+++ b/libc/time/strftime_l.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2004, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -84,6 +84,7 @@ extern char *tzname[];
# include <stddef.h>
# include <stdlib.h>
# include <string.h>
+# include <stdbool.h>
#else
# ifndef HAVE_MEMCPY
# define memcpy(d, s, n) bcopy ((s), (d), (n))
@@ -453,27 +454,9 @@ static CHAR_T const month_name[][10] =
# define ut 0
#endif
-#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
- /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
- Work around this bug by copying *tp before it might be munged. */
- size_t _strftime_copytm (char *, size_t, const char *,
- const struct tm * ut_argument_spec_iso) __THROW;
- size_t
- my_strftime (s, maxsize, format, tp ut_argument)
- CHAR_T *s;
- size_t maxsize;
- const CHAR_T *format;
- const struct tm *tp;
- ut_argument_spec
- {
- struct tm tmcopy;
- tmcopy = *tp;
- return _strftime_copytm (s, maxsize, format, &tmcopy ut_argument);
- }
-# undef my_strftime
-# define my_strftime _strftime_copytm
-#endif
-
+static size_t __strftime_internal (CHAR_T *, size_t, const CHAR_T *,
+ const struct tm *, bool ut_argument_spec_iso
+ LOCALE_PARAM_PROTO) __THROW;
/* Write information from TP into S according to the format
string FORMAT, writing no more that MAXSIZE characters
@@ -481,12 +464,38 @@ static CHAR_T const month_name[][10] =
characters written. If S is NULL, nothing will be written
anywhere, so to determine how many characters would be
written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */
+
size_t
my_strftime (s, maxsize, format, tp ut_argument LOCALE_PARAM)
+ CHAR_T *s;
+ size_t maxsize;
+ const CHAR_T *format;
+ const struct tm *tp;
+ ut_argument_spec
+ LOCALE_PARAM_DECL
+{
+#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
+ /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
+ Work around this bug by copying *tp before it might be munged. */
+ struct tm tmcopy;
+ tmcopy = *tp;
+ tp = &tmcopy;
+#endif
+ return __strftime_internal (s, maxsize, format, tp, false
+ ut_argument LOCALE_ARG);
+}
+#ifdef _LIBC
+libc_hidden_def (my_strftime)
+#endif
+
+static size_t
+__strftime_internal (s, maxsize, format, tp, tzset_called ut_argument
+ LOCALE_PARAM)
CHAR_T *s;
size_t maxsize;
const CHAR_T *format;
const struct tm *tp;
+ bool tzset_called;
ut_argument_spec
LOCALE_PARAM_DECL
{
@@ -559,7 +568,9 @@ my_strftime (s, maxsize, format, tp ut_argument LOCALE_PARAM)
/* POSIX.1 requires that local time zone information is used as
though strftime called tzset. */
# if HAVE_TZSET
- tzset ();
+ if (!tzset_called)
+ tzset ();
+ tzset_called = true;
# endif
}
#endif
@@ -834,10 +845,12 @@ my_strftime (s, maxsize, format, tp ut_argument LOCALE_PARAM)
subformat:
{
CHAR_T *old_start = p;
- size_t len = my_strftime (NULL, (size_t) -1, subfmt,
- tp ut_argument LOCALE_ARG);
- add (len, my_strftime (p, maxsize - i, subfmt,
- tp ut_argument LOCALE_ARG));
+ size_t len = __strftime_internal (NULL, (size_t) -1, subfmt,
+ tp, tzset_called ut_argument
+ LOCALE_ARG);
+ add (len, __strftime_internal (p, maxsize - i, subfmt,
+ tp, tzset_called ut_argument
+ LOCALE_ARG));
if (to_uppcase)
while (old_start < p)
@@ -1409,9 +1422,6 @@ my_strftime (s, maxsize, format, tp ut_argument LOCALE_PARAM)
*p = L_('\0');
return i;
}
-#ifdef _LIBC
-libc_hidden_def (my_strftime)
-#endif
#ifdef emacs
diff --git a/libc/time/tzfile.c b/libc/time/tzfile.c
index 44d661477..6a8bf89f9 100644
--- a/libc/time/tzfile.c
+++ b/libc/time/tzfile.c
@@ -243,7 +243,7 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
& ~(__alignof__ (struct leap) - 1));
leaps_idx = total_size;
total_size += num_leaps * sizeof (struct leap);
- tzspec_len = (trans_width == 8
+ tzspec_len = (sizeof (time_t) == 8 && trans_width == 8
? st.st_size - (ftello (f)
+ num_transitions * (8 + 1)
+ num_types * 6
@@ -263,14 +263,14 @@ __tzfile_read (const char *file, size_t extra, char **extrap)
types = (struct ttinfo *) ((char *) transitions + types_idx);
zone_names = (char *) types + num_types * sizeof (struct ttinfo);
leaps = (struct leap *) ((char *) transitions + leaps_idx);
- if (trans_width == 8)
- tzspec = (char *) leaps + num_leaps * sizeof (struct leap);
+ if (sizeof (time_t) == 8 && trans_width == 8)
+ tzspec = (char *) leaps + num_leaps * sizeof (struct leap) + extra;
else
tzspec = NULL;
if (extra > 0)
*extrap = (char *) &leaps[num_leaps];
- if (sizeof (time_t) == 4 || trans_width == 8)
+ if (sizeof (time_t) == 4 || __builtin_expect (trans_width == 8, 1))
{
if (__builtin_expect (fread_unlocked (transitions, trans_width + 1,
num_transitions, f)
@@ -596,7 +596,7 @@ __tzfile_compute (time_t timer, int use_localtime,
if (tzspec == NULL)
{
use_last:
- i = num_transitions - 1;
+ i = num_transitions;
goto found;
}
@@ -666,7 +666,8 @@ __tzfile_compute (time_t timer, int use_localtime,
i = hi;
found:
- /* assert (timer >= transitions[i - 1] && timer < transitions[i]); */
+ /* assert (timer >= transitions[i - 1]
+ && (i == num_transitions || timer < transitions[i])); */
__tzname[types[type_idxs[i - 1]].isdst]
= __tzstring (&zone_names[types[type_idxs[i - 1]].idx]);
size_t j = i;