diff options
| author | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
|---|---|---|
| committer | Jakub Jelinek <jakub@redhat.com> | 2007-07-12 18:26:36 +0000 |
| commit | 0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (patch) | |
| tree | 2ea1f8305970753e4a657acb2ccc15ca3eec8e2c /time | |
| parent | 7d58530341304d403a6626d7f7a1913165fe2f32 (diff) | |
| download | glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.tar.xz glibc-0ecb606cb6cf65de1d9fc8a919bceb4be476c602.zip | |
2.5-18.1
Diffstat (limited to 'time')
| -rw-r--r-- | time/Makefile | 5 | ||||
| -rw-r--r-- | time/adjtime.c | 37 | ||||
| -rw-r--r-- | time/asctime.c | 66 | ||||
| -rw-r--r-- | time/bug-asctime.c | 33 | ||||
| -rw-r--r-- | time/bug-asctime_r.c | 32 | ||||
| -rw-r--r-- | time/bug-mktime1.c | 17 | ||||
| -rw-r--r-- | time/clock.c | 32 | ||||
| -rw-r--r-- | time/ftime.c | 43 | ||||
| -rw-r--r-- | time/getitimer.c | 42 | ||||
| -rw-r--r-- | time/gettimeofday.c | 39 | ||||
| -rw-r--r-- | time/mktime.c | 73 | ||||
| -rw-r--r-- | time/setitimer.c | 44 | ||||
| -rw-r--r-- | time/settimeofday.c | 35 | ||||
| -rw-r--r-- | time/stime.c | 40 | ||||
| -rw-r--r-- | time/strptime_l.c | 57 | ||||
| -rw-r--r-- | time/sys/time.h | 20 | ||||
| -rw-r--r-- | time/time.c | 36 | ||||
| -rw-r--r-- | time/time.h | 5 | ||||
| -rw-r--r-- | time/tst-strptime.c | 22 | ||||
| -rw-r--r-- | time/tst-strptime2.c | 59 | ||||
| -rw-r--r-- | time/tst-strptime3.c | 55 | ||||
| -rw-r--r-- | time/tzfile.c | 111 |
22 files changed, 813 insertions, 90 deletions
diff --git a/time/Makefile b/time/Makefile index 7acc964fdc..8ce34e4565 100644 --- a/time/Makefile +++ b/time/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1991-2002,2003,2004 Free Software Foundation, Inc. +# Copyright (C) 1991-2003, 2004, 2005, 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 @@ -35,7 +35,8 @@ distribute := datemsk tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \ - tst-mktime3 + tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \ + tst-strptime3 include ../Rules diff --git a/time/adjtime.c b/time/adjtime.c new file mode 100644 index 0000000000..8645652188 --- /dev/null +++ b/time/adjtime.c @@ -0,0 +1,37 @@ +/* Copyright (C) 1991, 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sys/time.h> + +/* Adjust the current time of day by the amount in DELTA. + If OLDDELTA is not NULL, it is filled in with the amount + of time adjustment remaining to be done from the last `__adjtime' call. + This call is restricted to the super-user. */ +int +__adjtime (delta, olddelta) + const struct timeval *delta; + struct timeval *olddelta; +{ + __set_errno (ENOSYS); + return -1; +} +stub_warning (adjtime) + +weak_alias (__adjtime, adjtime) +#include <stub-tag.h> diff --git a/time/asctime.c b/time/asctime.c index f20b311bb5..dc4fd54f4e 100644 --- a/time/asctime.c +++ b/time/asctime.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,1993,1995-1997,2000,2002 Free Software Foundation, Inc. +/* Copyright (C) 1991,1993,1995-1997,2000,2002,2005 + 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 @@ -18,6 +19,7 @@ #include "../locale/localeinfo.h" #include <errno.h> +#include <limits.h> #include <stdio.h> #include <time.h> @@ -29,17 +31,9 @@ extern const struct locale_data _nl_C_LC_TIME attribute_hidden; static const char format[] = "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"; static char result[ 3+1+ 3+1+20+1+20+1+20+1+20+1+20+1 + 1]; -/* Returns a string of the form "Day Mon dd hh:mm:ss yyyy\n" - which is the representation of TP in that form. */ -char * -asctime (const struct tm *tp) -{ - return __asctime_r (tp, result); -} -libc_hidden_def (asctime) -char * -__asctime_r (const struct tm *tp, char *buf) +static char * +asctime_internal (const struct tm *tp, char *buf, size_t buflen) { if (tp == NULL) { @@ -47,15 +41,51 @@ __asctime_r (const struct tm *tp, char *buf) return NULL; } - if (sprintf (buf, format, - (tp->tm_wday < 0 || tp->tm_wday >= 7 ? - "???" : ab_day_name (tp->tm_wday)), - (tp->tm_mon < 0 || tp->tm_mon >= 12 ? - "???" : ab_month_name (tp->tm_mon)), - tp->tm_mday, tp->tm_hour, tp->tm_min, - tp->tm_sec, 1900 + tp->tm_year) < 0) + /* We limit the size of the year which can be printed. Using the %d + format specifier used the addition of 1900 would overflow the + number and a negative vaue is printed. For some architectures we + could in theory use %ld or an evern larger integer format but + this would mean the output needs more space. This would not be a + problem if the 'asctime_r' interface would be defined sanely and + a buffer size would be passed. */ + if (__builtin_expect (tp->tm_year > INT_MAX - 1900, 0)) + { + eoverflow: + __set_errno (EOVERFLOW); + return NULL; + } + + int n = __snprintf (buf, buflen, format, + (tp->tm_wday < 0 || tp->tm_wday >= 7 ? + "???" : ab_day_name (tp->tm_wday)), + (tp->tm_mon < 0 || tp->tm_mon >= 12 ? + "???" : ab_month_name (tp->tm_mon)), + tp->tm_mday, tp->tm_hour, tp->tm_min, + tp->tm_sec, 1900 + tp->tm_year); + if (n < 0) return NULL; + if (n >= buflen) + goto eoverflow; return buf; } + + +/* Like asctime, but write result to the user supplied buffer. The + buffer is only guaranteed to be 26 bytes in length. */ +char * +__asctime_r (const struct tm *tp, char *buf) +{ + return asctime_internal (tp, buf, 26); +} weak_alias (__asctime_r, asctime_r) + + +/* Returns a string of the form "Day Mon dd hh:mm:ss yyyy\n" + which is the representation of TP in that form. */ +char * +asctime (const struct tm *tp) +{ + return asctime_internal (tp, result, sizeof (result)); +} +libc_hidden_def (asctime) diff --git a/time/bug-asctime.c b/time/bug-asctime.c new file mode 100644 index 0000000000..0b04b475a8 --- /dev/null +++ b/time/bug-asctime.c @@ -0,0 +1,33 @@ +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <time.h> + + +static int +do_test (void) +{ + int result = 0; + time_t t = time (NULL); + struct tm *tp = localtime (&t); + tp->tm_year = INT_MAX; + errno = 0; + char *s = asctime (tp); + if (s != NULL || errno != EOVERFLOW) + { + puts ("asctime did not fail correctly"); + result = 1; + } + char buf[1000]; + errno = 0; + s = asctime_r (tp, buf); + if (s != NULL || errno != EOVERFLOW) + { + puts ("asctime_r did not fail correctly"); + result = 1; + } + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/time/bug-asctime_r.c b/time/bug-asctime_r.c new file mode 100644 index 0000000000..86651ef1c5 --- /dev/null +++ b/time/bug-asctime_r.c @@ -0,0 +1,32 @@ +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <time.h> + + +static int +do_test (void) +{ + int result = 0; + time_t t = time (NULL); + struct tm *tp = localtime (&t); + tp->tm_year = 10000 - 1900; + char buf[1000]; + errno = 0; + buf[26] = '\xff'; + char *s = asctime_r (tp, buf); + if (s != NULL || errno != EOVERFLOW) + { + puts ("asctime_r did not fail correctly"); + result = 1; + } + if (buf[26] != '\xff') + { + puts ("asctime_r overwrote 27th byte in buffer"); + result = 1; + } + return result; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/time/bug-mktime1.c b/time/bug-mktime1.c new file mode 100644 index 0000000000..e071273f05 --- /dev/null +++ b/time/bug-mktime1.c @@ -0,0 +1,17 @@ +#include <stdio.h> +#include <time.h> + + +static int +do_test (void) +{ + struct tm t2 = { 0, 0, 0, 1, 1, 2050 - 1900, 1, 1, 1 }; + time_t tt2 = mktime (&t2); + printf ("%ld\n", (long int) tt2); + if (sizeof (time_t) == 4 && tt2 != -1) + return 1; + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/time/clock.c b/time/clock.c new file mode 100644 index 0000000000..99dc5f47e0 --- /dev/null +++ b/time/clock.c @@ -0,0 +1,32 @@ +/* Copyright (C) 1991, 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/times.h> +#include <time.h> +#include <errno.h> + +/* Return the time used by the program so far (user time + system time). */ +clock_t +clock () +{ + __set_errno (ENOSYS); + return (clock_t) -1; +} + +stub_warning (clock) +#include <stub-tag.h> diff --git a/time/ftime.c b/time/ftime.c new file mode 100644 index 0000000000..94dfbcc98b --- /dev/null +++ b/time/ftime.c @@ -0,0 +1,43 @@ +/* Copyright (C) 1994, 1996, 1997, 2001 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <time.h> +#include <sys/timeb.h> + +int +ftime (timebuf) + struct timeb *timebuf; +{ + int save = errno; + struct tm tp; + + __set_errno (0); + if (time (&timebuf->time) == (time_t) -1 && errno != 0) + return -1; + timebuf->millitm = 0; + + if (__localtime_r (&timebuf->time, &tp) == NULL) + return -1; + + timebuf->timezone = tp.tm_gmtoff / 60; + timebuf->dstflag = tp.tm_isdst; + + __set_errno (save); + return 0; +} diff --git a/time/getitimer.c b/time/getitimer.c new file mode 100644 index 0000000000..d9f3063e1e --- /dev/null +++ b/time/getitimer.c @@ -0,0 +1,42 @@ +/* Copyright (C) 1991, 1994, 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stddef.h> +#include <errno.h> +#include <sys/time.h> + +/* Set *VALUE to the current setting of timer WHICH. + Return 0 on success, -1 on errors. */ +int +__getitimer (which, value) + enum __itimer_which which; + struct itimerval *value; +{ + if (value == NULL) + { + __set_errno (EINVAL); + return -1; + } + + __set_errno (ENOSYS); + return -1; +} +stub_warning (getitimer) + +weak_alias (__getitimer, getitimer) +#include <stub-tag.h> diff --git a/time/gettimeofday.c b/time/gettimeofday.c new file mode 100644 index 0000000000..f4a170c9e7 --- /dev/null +++ b/time/gettimeofday.c @@ -0,0 +1,39 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 2002 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 + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sys/time.h> + +#undef __gettimeofday + +/* Get the current time of day and timezone information, + putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. + Returns 0 on success, -1 on errors. */ +int +__gettimeofday (tv, tz) + struct timeval *tv; + struct timezone *tz; +{ + __set_errno (ENOSYS); + return -1; +} +stub_warning (gettimeofday) + +INTDEF(__gettimeofday) +weak_alias (__gettimeofday, gettimeofday) +#include <stub-tag.h> diff --git a/time/mktime.c b/time/mktime.c index c6ae56ee60..8f00c72e09 100644 --- a/time/mktime.c +++ b/time/mktime.c @@ -1,7 +1,7 @@ /* Convert a `struct tm' to a time_t value. - Copyright (C) 1993-1999, 2002, 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 1993-1999, 2002-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. - Contributed by Paul Eggert (eggert@twinsun.com). + Contributed by Paul Eggert <eggert@twinsun.com>. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -38,10 +38,11 @@ #include <limits.h> +#include <string.h> /* For the real memcpy prototype. */ + #if DEBUG # include <stdio.h> # include <stdlib.h> -# include <string.h> /* Make it work even if the system's libc has its own mktime routine. */ # define mktime my_mktime #endif /* DEBUG */ @@ -61,13 +62,38 @@ ? (a) >> (b) \ : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) -/* The extra casts work around common compiler bugs. */ +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if negative values of the signed integer type T use two's + complement, ones' complement, or signed magnitude representation, + respectively. Much GNU code assumes two's complement, but some + people like to be portable to all possible C hosts. */ +#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) +#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) +#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) + +/* True if the arithmetic type T is signed. */ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) -/* The outer cast is needed to work around a bug in Cray C 5.0.3.0. - It is necessary at least when t == time_t. */ -#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ - ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)) -#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t))) + +/* The maximum and minimum values for the integer type T. These + macros have undefined behavior if T is signed and has padding bits. + If this is a problem for you, please let us know how to fix it for + your host. */ +#define TYPE_MINIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) #ifndef TIME_T_MIN # define TIME_T_MIN TYPE_MINIMUM (time_t) @@ -80,8 +106,8 @@ /* Verify a requirement at compile-time (unlike assert, which is runtime). */ #define verify(name, assertion) struct name { char a[(assertion) ? 1 : -1]; } -verify (time_t_is_integer, (time_t) 0.5 == 0); -verify (twos_complement_arithmetic, -1 == ~1 + 1); +verify (time_t_is_integer, TYPE_IS_INTEGER (time_t)); +verify (twos_complement_arithmetic, TYPE_TWOS_COMPLEMENT (int)); /* The code also assumes that signed integer overflow silently wraps around, but this assumption can't be stated without causing a diagnostic on some hosts. */ @@ -190,10 +216,11 @@ guess_time_tm (long int year, long int yday, int hour, int min, int sec, /* Overflow occurred one way or another. Return the nearest result that is actually in range, except don't report a zero difference if the actual difference is nonzero, as that would cause a false - match. */ + match; and don't oscillate between two values, as that would + confuse the spring-forward gap detector. */ return (*t < TIME_T_MIDPOINT - ? TIME_T_MIN + (*t == TIME_T_MIN) - : TIME_T_MAX - (*t == TIME_T_MAX)); + ? (*t <= TIME_T_MIN + 1 ? *t + 1 : TIME_T_MIN) + : (TIME_T_MAX - 1 <= *t ? *t - 1 : TIME_T_MAX)); } /* Use CONVERT to convert *T to a broken down time in *TP. @@ -203,13 +230,12 @@ static struct tm * ranged_convert (struct tm *(*convert) (const time_t *, struct tm *), time_t *t, struct tm *tp) { - struct tm *r; + struct tm *r = convert (t, tp); - if (! (r = (*convert) (t, tp)) && *t) + if (!r && *t) { time_t bad = *t; time_t ok = 0; - struct tm tm; /* BAD is a known unconvertible time_t, and OK is a known good one. Use binary search to narrow the range betwee |
