about summary refs log tree commit diff
path: root/time/localtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'time/localtime.c')
-rw-r--r--time/localtime.c99
1 files changed, 13 insertions, 86 deletions
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)