summary refs log tree commit diff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/Makefile3
-rw-r--r--time/README4
-rw-r--r--time/gmtime.c29
-rw-r--r--time/localtime.c99
-rw-r--r--time/mktime.c2
-rw-r--r--time/offtime.c6
-rw-r--r--time/strftime.c1
-rw-r--r--time/tzfile.c30
-rw-r--r--time/tzset.c109
9 files changed, 142 insertions, 141 deletions
diff --git a/time/Makefile b/time/Makefile
index 123ba2d08a..c4945f7e4b 100644
--- a/time/Makefile
+++ b/time/Makefile
@@ -59,7 +59,9 @@ define nl
 
 
 endef
+ifneq ($(no_deps),t)
 -include $(addprefix $(objpfx)z.,$(tzfiles))
+endif
 
 # Make these absolute file names.
 installed-localtime-file := $(firstword $(filter /%,$(inst_localtime-file)) \
@@ -80,6 +82,7 @@ endif
 ifeq ($(have-ksh),yes)
 install-others += $(inst_zonedir)/iso3166.tab $(inst_zonedir)/zone.tab
 install-bin += tzselect
+generated += tzselect
 endif
 
 include ../Rules
diff --git a/time/README b/time/README
index c15f4f6f63..c189555c40 100644
--- a/time/README
+++ b/time/README
@@ -3,7 +3,7 @@ The source files
 	`zdump.c'
 	`tzselect.ksh'
 	`checktab.awk'
-come from the tzcode1997f package by Arthur David Olsen et.al.
+come from the tzcode1997g package by Arthur David Olsen et.al.
 
 The files
 	`africa'
@@ -25,4 +25,4 @@ The files
 	`zone.tab'
 	`leapseconds'
 	`yearistype'
-come from the tzdata1997g package by Arthur David Olsen et.al.
+come from the tzdata1997h package by Arthur David Olsen et.al.
diff --git a/time/gmtime.c b/time/gmtime.c
index f9627e7b62..2b388befb1 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Convert `time_t' to `struct tm' in UTC.
+   Copyright (C) 1991, 1993, 1995, 1996, 1997 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
@@ -16,19 +17,14 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <stddef.h>
 #include <time.h>
 
 /* Defined in localtime.c.  */
 extern struct tm _tmbuf;
 
-/* Return the `struct tm' representation of *T in UTC.	*/
-struct tm *
-gmtime (t)
-     const time_t *t;
-{
-  return __gmtime_r (t, &_tmbuf);
-}
+/* Prototype for the internal function to get information based on TZ.  */
+extern struct tm *__tz_convert __P ((const time_t *t, int use_localtime,
+				     struct tm *tp));
 
 
 /* Return the `struct tm' representation of *T in UTC,
@@ -38,12 +34,15 @@ __gmtime_r (t, tp)
      const time_t *t;
      struct tm *tp;
 {
-  __offtime (t, 0L, tp);
+  return __tz_convert (t, 0, tp);
+}
+weak_alias (__gmtime_r, gmtime_r)
 
-  tp->tm_isdst = 0;
-  tp->tm_gmtoff = 0L;
-  tp->tm_zone = "GMT";
 
-  return tp;
+/* Return the `struct tm' representation of *T in UTC.	*/
+struct tm *
+gmtime (t)
+     const time_t *t;
+{
+  return __tz_convert (t, 0, &_tmbuf);
 }
-weak_alias (__gmtime_r, gmtime_r)
diff --git a/time/localtime.c b/time/localtime.c
index 6b7c9f394c..3d8d8fbd10 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -17,106 +17,33 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <errno.h>
 #include <time.h>
-#include <bits/libc-lock.h>
 
 /* The C Standard says that localtime and gmtime return the same pointer.  */
 struct tm _tmbuf;
 
 /* Prototype for the internal function to get information based on TZ.  */
-extern void __tzset_internal __P ((int always));
-extern int __tz_compute __P ((time_t timer, struct tm *tp));
-extern int __tzfile_compute __P ((time_t timer,
-				  long int *leap_correct, int *leap_hit));
+extern struct tm *__tz_convert __P ((const time_t *t, int use_localtime,
+				     struct tm *tp));
 
-extern int __use_tzfile;
 
-/* This lock is defined in tzset.c and locks all the data defined there
-   and in tzfile.c; the internal functions do no locking themselves.
-   This lock is only taken here and in `tzset'.  */
-__libc_lock_define (extern, __tzset_lock)
-
-
-/* Return the `struct tm' representation of *TIMER in the local timezone.  */
-static struct tm *
-localtime_internal (const time_t *timer, struct tm *tp)
-{
-  long int leap_correction;
-  int leap_extra_secs;
-
-  if (timer == NULL)
-    {
-      __set_errno (EINVAL);
-      return NULL;
-    }
-
-  if (__use_tzfile)
-    {
-      if (! __tzfile_compute (*timer, &leap_correction, &leap_extra_secs))
-	tp = NULL;
-    }
-  else
-    {
-      tp = __gmtime_r (timer, tp);
-      if (tp && ! __tz_compute (*timer, tp))
-	tp = NULL;
-      leap_correction = 0L;
-      leap_extra_secs = 0;
-    }
-
-  if (tp)
-    {
-      __offtime (timer, __timezone - leap_correction, tp);
-      tp->tm_sec += leap_extra_secs;
-      tp->tm_isdst = __daylight;
-      tp->tm_gmtoff = __timezone;
-      tp->tm_zone = __tzname[__daylight];
-    }
-
-  return tp;
-}
-
-
-/* POSIX.1 8.3.7.2 says that localtime_r is not required to set
-   tzname.  This is a good idea since this allows at least a bit more
-   parallelism.  */
 
+/* Return the `struct tm' representation of *T in local time,
+   using *TP to store the result.  */
 struct tm *
-localtime (timer)
-     const time_t *timer;
+__localtime_r (t, tp)
+     const time_t *t;
+     struct tm *tp;
 {
-  struct tm *result;
-
-  __libc_lock_lock (__tzset_lock);
-
-  /* Update internal database according to current TZ setting.  */
-  __tzset_internal (1);
-
-  result = localtime_internal (timer, &_tmbuf);
-
-  __libc_lock_unlock (__tzset_lock);
-
-  return result;
+  return __tz_convert (t, 1, tp);
 }
+weak_alias (__localtime_r, localtime_r)
 
 
+/* Return the `struct tm' representation of *T in local time.  */
 struct tm *
-__localtime_r (timer, tp)
-     const time_t *timer;
-     struct tm *tp;
+localtime (t)
+     const time_t *t;
 {
-  struct tm *result;
-
-  __libc_lock_lock (__tzset_lock);
-
-  /* Make sure the database is initialized.  */
-  __tzset_internal (0);
-
-  result = localtime_internal (timer, tp);
-
-  __libc_lock_unlock (__tzset_lock);
-
-  return result;
+  return __tz_convert (t, 1, &_tmbuf);
 }
-weak_alias (__localtime_r, localtime_r)
diff --git a/time/mktime.c b/time/mktime.c
index 5012888967..1573cc79a9 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -225,10 +225,10 @@ __mktime_internal (tp, convert, offset)
 	       [mon_remainder + 12 * negative_mon_remainder])
 	      + mday - 1);
 
+  int sec_requested = sec;
 #if LEAP_SECONDS_POSSIBLE
   /* Handle out-of-range seconds specially,
      since ydhms_tm_diff assumes every minute has 60 seconds.  */
-  int sec_requested = sec;
   if (sec < 0)
     sec = 0;
   if (59 < sec)
diff --git a/time/offtime.c b/time/offtime.c
index f13c8a38ae..a4b59ed209 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -33,8 +33,8 @@ __offtime (t, offset, tp)
      long int offset;
      struct tm *tp;
 {
-  register long int days, rem, y;
-  register const unsigned short int *ip;
+  long int days, rem, y;
+  const unsigned short int *ip;
 
   days = *t / SECS_PER_DAY;
   rem = *t % SECS_PER_DAY;
@@ -75,7 +75,7 @@ __offtime (t, offset, tp)
   tp->tm_year = y - 1900;
   tp->tm_yday = days;
   ip = __mon_yday[__isleap(y)];
-  for (y = 11; days < ip[y]; --y)
+  for (y = 11; days < (long int) ip[y]; --y)
     continue;
   days -= ip[y];
   tp->tm_mon = y;
diff --git a/time/strftime.c b/time/strftime.c
index 891d301f5c..4ecbc5a519 100644
--- a/time/strftime.c
+++ b/time/strftime.c
@@ -132,7 +132,6 @@ extern char *tzname[];
 #ifdef _LIBC
 # define gmtime_r __gmtime_r
 # define localtime_r __localtime_r
-extern int __tz_compute __P ((time_t timer, const struct tm *tm));
 # define tzname __tzname
 # define tzset __tzset
 #else
diff --git a/time/tzfile.c b/time/tzfile.c
index aeec637b3b..9289de63a0 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -112,8 +112,8 @@ __tzfile_read (const char *file)
     /* No user specification; use the site-wide default.  */
     file = TZDEFAULT;
   else if (*file == '\0')
-    /* User specified the empty string; use UTC explicitly.  */
-    file = "Universal";
+    /* User specified the empty string; use UTC with no leap seconds.  */
+    return;
   else
     {
       /* We must not allow to read an arbitrary file in a setuid
@@ -411,19 +411,23 @@ find_transition (time_t timer)
 }
 
 int
-__tzfile_compute (time_t timer, long int *leap_correct, int *leap_hit)
+__tzfile_compute (time_t timer, int use_localtime,
+		  long int *leap_correct, int *leap_hit)
 {
-  struct ttinfo *info;
   register size_t i;
 
-  info = find_transition (timer);
-  __daylight = info->isdst;
-  __timezone = info->offset;
-  for (i = 0; i < num_types && i < sizeof (__tzname) / sizeof (__tzname[0]);
-       ++i)
-    __tzname[types[i].isdst] = &zone_names[types[i].idx];
-  if (info->isdst < sizeof (__tzname) / sizeof (__tzname[0]))
-    __tzname[info->isdst] = &zone_names[info->idx];
+  if (use_localtime)
+    {
+      struct ttinfo *info = find_transition (timer);
+      __daylight = info->isdst;
+      __timezone = info->offset;
+      for (i = 0;
+	   i < num_types && i < sizeof (__tzname) / sizeof (__tzname[0]);
+	   ++i)
+	__tzname[types[i].isdst] = &zone_names[types[i].idx];
+      if (info->isdst < sizeof (__tzname) / sizeof (__tzname[0]))
+	__tzname[info->isdst] = &zone_names[info->idx];
+    }
 
   *leap_correct = 0L;
   *leap_hit = 0;
@@ -455,7 +459,7 @@ __tzfile_compute (time_t timer, long int *leap_correct, int *leap_hit)
   return 1;
 }
 
-void
+static void
 compute_tzname_max (size_t chars)
 {
   extern size_t __tzname_cur_max; /* Defined in tzset.c. */
diff --git a/time/tzset.c b/time/tzset.c
index 49935c04d3..6c16091ef5 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -17,6 +17,8 @@
    Boston, MA 02111-1307, USA.  */
 
 #include <ctype.h>
+#include <errno.h>
+#include <bits/libc-lock.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -26,15 +28,19 @@
 /* Defined in mktime.c.  */
 extern const unsigned short int __mon_yday[2][13];
 
+/* Defined in localtime.c.  */
+extern struct tm _tmbuf;
+
 #define NOID
 #include "tzfile.h"
 
 extern int __use_tzfile;
 extern void __tzfile_read __P ((const char *file));
+extern int __tzfile_compute __P ((time_t timer, int use_localtime,
+				  long int *leap_correct, int *leap_hit));
 extern void __tzfile_default __P ((const char *std, const char *dst,
 				   long int stdoff, long int dstoff));
 extern char * __tzstring __P ((const char *string));
-extern int __tz_compute __P ((time_t timer, const struct tm *tm));
 
 char *__tzname[2] = { (char *) "GMT", (char *) "GMT" };
 int __daylight = 0;
@@ -44,6 +50,9 @@ weak_alias (__tzname, tzname)
 weak_alias (__daylight, daylight)
 weak_alias (__timezone, timezone)
 
+/* This locks all the state variables in tzfile.c and this file.  */
+__libc_lock_define (static, tzset_lock)
+
 
 #define	min(a, b)	((a) < (b) ? (a) : (b))
 #define	max(a, b)	((a) > (b) ? (a) : (b))
@@ -74,6 +83,8 @@ static tz_rule tz_rules[2];
 
 
 static int compute_change __P ((tz_rule *rule, int year));
+static int tz_compute __P ((time_t timer, const struct tm *tm));
+static void tzset_internal __P ((int always));
 
 /* Header for a list of buffers containing time zone strings.  */
 struct tzstring_head
@@ -139,9 +150,8 @@ __tzstring (string)
 static char *old_tz = NULL;
 
 /* Interpret the TZ envariable.  */
-void __tzset_internal __P ((int always));
-void
-__tzset_internal (always)
+static void
+tzset_internal (always)
      int always;
 {
   static int is_initialized = 0;
@@ -426,7 +436,11 @@ size_t __tzname_cur_max;
 long int
 __tzname_max ()
 {
-  __tzset_internal (0);
+  __libc_lock_lock (tzset_lock);
+
+  tzset_internal (0);
+
+  __libc_lock_unlock (tzset_lock);
 
   return __tzname_cur_max;
 }
@@ -473,8 +487,9 @@ compute_change (rule, year)
     case M:
       /* Mm.n.d - Nth "Dth day" of month M.  */
       {
-	register int i, d, m1, yy0, yy1, yy2, dow;
-	register const unsigned short int *myday =
+	unsigned int i;
+	int d, m1, yy0, yy1, yy2, dow;
+	const unsigned short int *myday =
 	  &__mon_yday[__isleap (year)][rule->m];
 
 	/* First add SECSPERDAY for each day in months before M.  */
@@ -496,7 +511,7 @@ compute_change (rule, year)
 	  d += 7;
 	for (i = 1; i < rule->n; ++i)
 	  {
-	    if (d + 7 >= myday[0] - myday[-1])
+	    if (d + 7 >= (int) myday[0] - myday[-1])
 	      break;
 	    d += 7;
 	  }
@@ -519,13 +534,11 @@ compute_change (rule, year)
 /* Figure out the correct timezone for *TIMER and TM (which must be the same)
    and set `__tzname', `__timezone', and `__daylight' accordingly.
    Return nonzero on success, zero on failure.  */
-int
-__tz_compute (timer, tm)
+static int
+tz_compute (timer, tm)
      time_t timer;
      const struct tm *tm;
 {
-  __tzset_internal (0);
-
   if (! compute_change (&tz_rules[0], 1900 + tm->tm_year) ||
       ! compute_change (&tz_rules[1], 1900 + tm->tm_year))
     return 0;
@@ -548,20 +561,15 @@ __tz_compute (timer, tm)
   return 1;
 }
 
-#include <bits/libc-lock.h>
-
-/* This locks all the state variables in tzfile.c and this file.  */
-__libc_lock_define (, __tzset_lock)
-
 /* Reinterpret the TZ environment variable and set `tzname'.  */
 #undef tzset
 
 void
 __tzset (void)
 {
-  __libc_lock_lock (__tzset_lock);
+  __libc_lock_lock (tzset_lock);
 
-  __tzset_internal (1);
+  tzset_internal (1);
 
   if (!__use_tzfile)
     {
@@ -570,6 +578,67 @@ __tzset (void)
       __tzname[1] = (char *) tz_rules[1].name;
     }
 
-  __libc_lock_unlock (__tzset_lock);
+  __libc_lock_unlock (tzset_lock);
 }
 weak_alias (__tzset, tzset)
+
+/* Return the `struct tm' representation of *TIMER in the local timezone.
+   Use local time if USE_LOCALTIME is nonzero, UTC otherwise.  */
+struct tm *
+__tz_convert (const time_t *timer, int use_localtime, struct tm *tp)
+{
+  long int leap_correction;
+  int leap_extra_secs;
+
+  if (timer == NULL)
+    {
+      __set_errno (EINVAL);
+      return NULL;
+    }
+
+  __libc_lock_lock (tzset_lock);
+
+  /* Update internal database according to current TZ setting.
+     POSIX.1 8.3.7.2 says that localtime_r is not required to set tzname.
+     This is a good idea since this allows at least a bit more parallelism.
+     By analogy we apply the same rule to gmtime_r.  */
+  tzset_internal (tp == &_tmbuf);
+
+  if (__use_tzfile)
+    {
+      if (! __tzfile_compute (*timer, use_localtime,
+			      &leap_correction, &leap_extra_secs))
+	tp = NULL;
+    }
+  else
+    {
+      __offtime (timer, 0, tp);
+      if (! tz_compute (*timer, tp))
+	tp = NULL;
+      leap_correction = 0L;
+      leap_extra_secs = 0;
+    }
+
+  if (tp)
+    {
+      if (use_localtime)
+	{
+	  tp->tm_isdst = __daylight;
+	  tp->tm_zone = __tzname[__daylight];
+	  tp->tm_gmtoff = __timezone;
+	}
+      else
+	{
+	  tp->tm_isdst = 0;
+	  tp->tm_zone = "GMT";
+	  tp->tm_gmtoff = 0L;
+	}
+
+      __offtime (timer, tp->tm_gmtoff - leap_correction, tp);
+      tp->tm_sec += leap_extra_secs;
+    }
+
+  __libc_lock_unlock (tzset_lock);
+
+  return tp;
+}