aboutsummaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
Diffstat (limited to 'time')
-rw-r--r--time/gmtime.c18
-rw-r--r--time/localtime.c28
-rw-r--r--time/mktime.c29
-rw-r--r--time/offtime.c38
-rw-r--r--time/time.h31
-rw-r--r--time/timegm.c2
6 files changed, 101 insertions, 45 deletions
diff --git a/time/gmtime.c b/time/gmtime.c
index f09baef..93fba65 100644
--- a/time/gmtime.c
+++ b/time/gmtime.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1993, 1995 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
@@ -20,14 +20,28 @@ Cambridge, MA 02139, 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 *
DEFUN(gmtime, (t), CONST time_t *t)
{
- struct tm *tp = __offtime (t, 0L);
+ return __gmtime_r (t, &_tmbuf);
+}
+
+/* Return the `struct tm' representation of *T in UTC,
+ using *TP to store the result. */
+struct tm *
+DEFUN(__gmtime_r, (t, tp),
+ CONST time_t *t AND struct tm *tp)
+{
+ __offtime (t, 0L, tp);
+ tp->tm_isdst = 0;
tp->tm_gmtoff = 0L;
tp->tm_zone = "GMT";
return tp;
}
+weak_alias (__gmtime_r, gmtime_r)
diff --git a/time/localtime.c b/time/localtime.c
index 5743347..4c68ab2 100644
--- a/time/localtime.c
+++ b/time/localtime.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1995 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,24 +16,29 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
-#include <stddef.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <errno.h>
#include <time.h>
+/* The C Standard says that localtime and gmtime return the same pointer. */
+struct tm _tmbuf;
/* Return the `struct tm' representation of *TIMER in the local timezone. */
struct tm *
localtime (timer)
const time_t *timer;
{
+ return __localtime_r (timer, &_tmbuf);
+}
+
+struct tm *
+__localtime_r (timer, tp)
+ const time_t *timer;
+ struct tm *tp;
+{
extern int __use_tzfile;
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));
- register struct tm *tp;
long int leap_correction;
int leap_extra_secs;
@@ -57,21 +62,22 @@ localtime (timer)
}
else
{
- tp = gmtime (timer);
- if (tp == NULL)
+ struct tm *gmtp = __gmtime_r (timer, tp);
+ if (gmtp == NULL)
return NULL;
- if (! __tz_compute (*timer, tp))
+ if (! __tz_compute (*timer, gmtp))
return NULL;
leap_correction = 0L;
leap_extra_secs = 0;
}
- tp = __offtime (timer, __timezone - leap_correction);
+ __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;
}
+weak_alias (__localtime_r, localtime_r)
diff --git a/time/mktime.c b/time/mktime.c
index f86496a..5b91c15 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -217,9 +217,9 @@ do_normalization (tmptr)
#define BAD_STRUCT_TM ((time_t) -1)
time_t
-_mktime_internal (timeptr, producer)
+__mktime_internal (timeptr, producer)
struct tm *timeptr;
- struct tm *(*producer) __P ((const time_t *));
+ struct tm *(*producer) __P ((const time_t *, struct tm *));
{
struct tm our_tm; /* our working space */
struct tm *me = &our_tm; /* a pointer to the above */
@@ -276,6 +276,7 @@ _mktime_internal (timeptr, producer)
{
struct tm *guess_tm;
+ struct tm guess_struct;
time_t guess = 0;
time_t distance = 0;
time_t last_distance = 0;
@@ -288,7 +289,7 @@ _mktime_internal (timeptr, producer)
times_through_search++;
- guess_tm = (*producer) (&guess);
+ guess_tm = (*producer) (&guess, &guess_struct);
#ifdef DEBUG
if (debugging_enabled)
@@ -399,6 +400,26 @@ _mktime_internal (timeptr, producer)
return result;
}
+#if ! HAVE_LOCALTIME_R && ! defined (localtime_r)
+#ifdef _LIBC
+#define localtime_r __localtime_r
+#else
+/* Approximate localtime_r as best we can in its absence. */
+#define localtime_r my_localtime_r /* Avoid clash with system localtime_r. */
+static struct tm *
+localtime_r (t, tp)
+ const time_t *t;
+ struct tm *tp;
+{
+ struct tm *l = localtime (t);
+ if (! l)
+ return NULL;
+ *tp = *l;
+ return tp;
+}
+#endif /* ! _LIBC */
+#endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
+
time_t
#ifdef DEBUG /* make it work even if the system's
libc has it's own mktime routine */
@@ -408,7 +429,7 @@ mktime (timeptr)
#endif
struct tm *timeptr;
{
- return _mktime_internal (timeptr, localtime);
+ return __mktime_internal (timeptr, localtime_r);
}
#ifdef weak_alias
diff --git a/time/offtime.c b/time/offtime.c
index a392a47..e588c4c 100644
--- a/time/offtime.c
+++ b/time/offtime.c
@@ -26,19 +26,17 @@ extern CONST unsigned short int __mon_lengths[2][12];
#define SECS_PER_HOUR (60 * 60)
#define SECS_PER_DAY (SECS_PER_HOUR * 24)
-/* Returns the `struct tm' representation of *T,
- offset OFFSET seconds east of UCT. */
-struct tm *
-DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
+/* Compute the `struct tm' representation of *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
+void
+DEFUN(__offtime, (t, offset, tp),
+ CONST time_t *t AND long int offset AND struct tm *tp)
{
- static struct tm tbuf;
register long int days, rem;
register int y;
register CONST unsigned short int *ip;
- if (t == NULL)
- return NULL;
-
days = *t / SECS_PER_DAY;
rem = *t % SECS_PER_DAY;
rem += offset;
@@ -52,14 +50,14 @@ DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
rem -= SECS_PER_DAY;
++days;
}
- tbuf.tm_hour = rem / SECS_PER_HOUR;
+ tp->tm_hour = rem / SECS_PER_HOUR;
rem %= SECS_PER_HOUR;
- tbuf.tm_min = rem / 60;
- tbuf.tm_sec = rem % 60;
+ tp->tm_min = rem / 60;
+ tp->tm_sec = rem % 60;
/* January 1, 1970 was a Thursday. */
- tbuf.tm_wday = (4 + days) % 7;
- if (tbuf.tm_wday < 0)
- tbuf.tm_wday += 7;
+ tp->tm_wday = (4 + days) % 7;
+ if (tp->tm_wday < 0)
+ tp->tm_wday += 7;
y = 1970;
while (days >= (rem = __isleap(y) ? 366 : 365))
{
@@ -71,14 +69,12 @@ DEFUN(__offtime, (t, offset), CONST time_t *t AND long int offset)
--y;
days += __isleap(y) ? 366 : 365;
}
- tbuf.tm_year = y - 1900;
- tbuf.tm_yday = days;
+ tp->tm_year = y - 1900;
+ tp->tm_yday = days;
ip = __mon_lengths[__isleap(y)];
for (y = 0; days >= ip[y]; ++y)
days -= ip[y];
- tbuf.tm_mon = y;
- tbuf.tm_mday = days + 1;
- tbuf.tm_isdst = -1;
-
- return &tbuf;
+ tp->tm_mon = y;
+ tp->tm_mday = days + 1;
+ tp->tm_isdst = -1;
}
diff --git a/time/time.h b/time/time.h
index 7070881..6d52e94 100644
--- a/time/time.h
+++ b/time/time.h
@@ -111,8 +111,9 @@ extern time_t mktime __P ((struct tm *__tp));
/* Subroutine of `mktime'. Return the `time_t' representation of TP and
normalize TP, given that a `struct tm *' maps to a `time_t' as performed
by FUNC. */
-extern time_t _mktime_internal __P ((struct tm *__tp,
- struct tm *(*__func) (const time_t *)));
+extern time_t __mktime_internal __P ((struct tm *__tp,
+ struct tm *(*__func) (const time_t *,
+ struct tm *)));
/* Format TP into S according to FORMAT.
@@ -130,10 +131,28 @@ extern struct tm *gmtime __P ((__const time_t *__timer));
of *TIMER in the local timezone. */
extern struct tm *localtime __P ((__const time_t *__timer));
-/* Return the `struct tm' representation of *TIMER,
- offset OFFSET seconds east of Universal Coordinated Time. */
-extern struct tm *__offtime __P ((__const time_t *__timer,
- long int __offset));
+#ifdef __USE_REENTRANT
+/* Return the `struct tm' representation of *TIMER in UTC,
+ using *TP to store the result. */
+extern struct tm *__gmtime_r __P ((__const time_t *__timer,
+ struct tm *__tp));
+extern struct tm *gmtime_r __P ((__const time_t *__timer,
+ struct tm *__tp));
+
+/* Return the `struct tm' representation of *TIMER in local time,
+ using *TP to store the result. */
+extern struct tm *__localtime_r __P ((__const time_t *__timer,
+ struct tm *__tp));
+extern struct tm *localtime_r __P ((__const time_t *__timer,
+ struct tm *__tp));
+#endif
+
+/* Compute the `struct tm' representation of *T,
+ offset OFFSET seconds east of UTC,
+ and store year, yday, mon, mday, wday, hour, min, sec into *TP. */
+extern void __offtime __P ((__const time_t *__timer,
+ long int __offset,
+ struct tm *__TP));
/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
that is the representation of TP in this format. */
diff --git a/time/timegm.c b/time/timegm.c
index dc80f78..f63aac9 100644
--- a/time/timegm.c
+++ b/time/timegm.c
@@ -23,5 +23,5 @@ timegm (tmp)
struct tm *const tmp;
{
tmp->tm_isdst = 0;
- return _mktime_internal (tmp, gmtime);
+ return __mktime_internal (tmp, __gmtime_r);
}