diff options
-rw-r--r-- | ChangeLog | 48 | ||||
-rw-r--r-- | errno.h | 12 | ||||
-rw-r--r-- | math/math.h | 2 | ||||
-rw-r--r-- | misc/efgcvt_r.c | 4 | ||||
-rw-r--r-- | stdlib/stdlib.h | 4 | ||||
-rw-r--r-- | sysdeps/mach/hurd/fpathconf.c | 2 | ||||
-rw-r--r-- | sysdeps/mach/hurd/pathconf.c | 2 | ||||
-rw-r--r-- | time/gmtime.c | 18 | ||||
-rw-r--r-- | time/localtime.c | 28 | ||||
-rw-r--r-- | time/mktime.c | 29 | ||||
-rw-r--r-- | time/offtime.c | 38 | ||||
-rw-r--r-- | time/time.h | 31 | ||||
-rw-r--r-- | time/timegm.c | 2 |
13 files changed, 166 insertions, 54 deletions
@@ -1,5 +1,53 @@ +Mon Sep 18 12:39:22 1995 Paul Eggert <eggert@twinsun.com> + + * mktime.c (localtime_r): Add substitute if the system doesn't + provide one. + +Mon Sep 18 14:39:20 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + + * time/gmtime.c (gmtime_r): Define as weak alias. + * time/localtime.c (localtime_r): Define as weak alias. + * time/time.h [__USE_REENTRANT] (gmtime_r, localtime_r): Declare them. + + * errno.h: Only define _ERRNO_H #ifndef __need_Emath. + #undef __need_Emath after including errnos.h. + [_ERRNO_H]: Protect decls with this. + +Sun Sep 17 08:22:12 1995 Paul Eggert <eggert@twinsun.com> + + Fix mktime so that it does not write over localtime's returned value. + * localtime.c (__localtime_r): New function, with extra arg + specifying where to store result. + (localtime): Use it. + (_tmbuf): New var. + * gmtime.c (__gmtime_r, gmtime, _tmbuf): Likewise. + * mktime.c (__mktime_internal): Conversion function is now + __localtime_r style, not localtime style. + (mktime): Pass __localtime_r, not localtime. + * timegm.c (timegm): Pass __gmtime_r, not gmtime. + * offtime.c (__offtime): New arg specifying where to store result. + * time.h (__mktime_internal, __offtime): Adjust decls accordingly. + (__gmtime_r, __localtime_r): New decls. + + * time/localtime.c: <stddef.h>, <ctype.h>, <stdio.h>, + <stdlib.h>, <string.h>: Remove includes. + <errno.h>: Add include. + + * time/mktime.c, time/time.h, time/timegm.c (__mktime_internal): + Renamed from _mktime_internal to avoid namespace pollution. + + * time/gmtime.c: Clear tm_isdst. + Mon Sep 18 01:58:40 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> + * misc/efgcvt_r.c (ecvt_r, fcvt_r): Last arg is size_t, not int. + * stdlib/stdlib.h (ecvt_r, fcvt_r): Fix type of last arg: make it + size_t. + + * sysdeps/mach/hurd/fpathconf.c: Call __io_pathconf instead of + __file_pathconf. + * sysdeps/mach/hurd/pathconf.c: Likewise. + * Makefile (subdirs): Add sysvipc. * stdlib/srand48_r.c (srand48_r): Use UL suffix for huge constant. @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1992, 1993, 1994, 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 @@ -22,14 +22,21 @@ Cambridge, MA 02139, USA. */ #ifndef _ERRNO_H +/* The includer defined __need_Emath if he wants only the definitions + of EDOM and ERANGE, and not everything else. */ +#ifndef __need_Emath #define _ERRNO_H 1 #include <features.h> +#endif __BEGIN_DECLS -/* Get the error number constants. */ +/* Get the error number constants from the system-specific file. + This file will test __need_Emath and _ERRNO_H. */ #include <errnos.h> +#undef __need_Emath +#ifdef _ERRNO_H /* Declare the `errno' variable. */ extern int errno; @@ -41,5 +48,6 @@ extern char *program_invocation_name, *program_invocation_short_name; #endif __END_DECLS +#endif #endif /* errno.h */ diff --git a/math/math.h b/math/math.h index 51ba57c088..c30928de30 100644 --- a/math/math.h +++ b/math/math.h @@ -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 diff --git a/misc/efgcvt_r.c b/misc/efgcvt_r.c index fb0d5917c2..099b349414 100644 --- a/misc/efgcvt_r.c +++ b/misc/efgcvt_r.c @@ -29,7 +29,7 @@ fcvt_r (value, ndigit, decpt, sign, buf, len) double value; int ndigit, *decpt, *sign; char *buf; - int len; + size_t len; { int n, i; @@ -64,7 +64,7 @@ ecvt_r (value, ndigit, decpt, sign, buf, len) double value; int ndigit, *decpt, *sign; char *buf; - int len; + size_t len; { ndigit -= (int) floor (log10 (value)); if (ndigit < 0) diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h index c6c504a143..ba5a231abf 100644 --- a/stdlib/stdlib.h +++ b/stdlib/stdlib.h @@ -409,9 +409,9 @@ char *gcvt __P ((double __value, int __ndigit, char *__buf)); /* Reentrant version of the functions above which provide their own buffers. */ int ecvt_r __P ((double __value, int __ndigit, int *__decpt, int *sign, - char *__buf, int *__len)); + char *__buf, size_t __len)); int fcvt_r __P ((double __value, int __ndigit, int *__decpt, int *sign, - char *__buf, int *__len)); + char *__buf, size_t __len)); #endif diff --git a/sysdeps/mach/hurd/fpathconf.c b/sysdeps/mach/hurd/fpathconf.c index 1899062741..f5e6579ee8 100644 --- a/sysdeps/mach/hurd/fpathconf.c +++ b/sysdeps/mach/hurd/fpathconf.c @@ -29,7 +29,7 @@ __fpathconf (int fd, int name) error_t err; long int value; - if (err = HURD_DPORT_USE (fd, __file_pathconf (port, name, &value))) + if (err = HURD_DPORT_USE (fd, __io_pathconf (port, name, &value))) return __hurd_dfail (fd, err), -1L; return value; diff --git a/sysdeps/mach/hurd/pathconf.c b/sysdeps/mach/hurd/pathconf.c index f7923ae967..0b27b32b07 100644 --- a/sysdeps/mach/hurd/pathconf.c +++ b/sysdeps/mach/hurd/pathconf.c @@ -31,7 +31,7 @@ __pathconf (const char *file, int name) file_t port = __file_name_lookup (file, 0, 0); if (port == MACH_PORT_NULL) return -1L; - err = __file_pathconf (port, name, &value); + err = __io_pathconf (port, name, &value); __mach_port_deallocate (__mach_task_self (), port); if (err) return __hurd_fail (err), -1L; diff --git a/time/gmtime.c b/time/gmtime.c index f09baef5f2..93fba659be 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 5743347641..4c68ab22dc 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 f86496a941..5b91c15f81 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 a392a47e89..e588c4c66b 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 7070881949..6d52e943eb 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 dc80f78683..f63aac94ca 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); } |