lib/mktime.c


Log

Author Commit Date CI Message
Ulrich Drepper 5490f5a9 2008-07-23T16:19:15 mktime.c: normalize tp->tm_isdst value to -1/0/1. * lib/mktime.c (__mktime_internal): Normalize tp->tm_isdst value. Reported by Michael Ringe <Michael.Ringe@gmx.de> in <http://sourceware.org/bugzilla/show_bug.cgi?id=6723>.
Paul Eggert 3ac95524 2007-02-12T18:49:19 New module 'time', so that apps can include <time.h> as per POSIX and GNU instead of separate include files like time_r.h and timegm.h. This implementation tries out a simpler approach for replacing decls in standard include files (as compared to the string module), somewhat as an experiment. * config/srclist.txt: Comment out mktime.c for now. * doc/gnulib-tool.texi (Initial import): Don't use time_r as an example since it doesn't apply any more. Use generic wording instead. * MODULES.html.sh (Support for systems lacking POSIX:2001): New module 'time'. * lib/time_.h, m4/time_h.m4, modules/time: New files. * lib/strptime.h, lib/time_r.h, lib/timegm.h: Remove. * lib/mktime.c: Include config.h depending on _LIBC, not HAVE_CONFIG_H. Don't include <sys/types.h>; no longer needed since we assume C89. * lib/mktime.c: Don't include "time_r.h"; no longer needed. * lib/strftime.c: Likewise. * lib/time_r.c: Likewise. * lib/nanosleep.c (nanosleep): #undef after include files, not before. * lib/nanosleep.c: Include <time.h> first, to check interface. * lib/strptime.c: Likewise. * lib/time_r.c: Likewise. * lib/timegm.c: Likewise. * lib/strptime.c: Don't include strptime.h or time_r.h; no longer needed. * lib/timegm.c: Don't include timegm.h; no longer needed. * lib/timespec.h: Don't include <sys/time.h> before <time.h>; time.h now handles any problems in that area. (struct timespec, nanosleep): Remove; time.h now arranges for these. * lib/xnanosleep.c: Don't include timespec.h; no longer needed now that time.h defines struct timespec. * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Check that nanosleep is declared. Set REPLACE_NANOSLEEP. Don't AC_DEFINE nanosleep; the time module now handles that. * m4/strptime.m4 (gl_FUNC_STPRTIME): Set REPLACE_STRPTIME. * m4/time_r.m4 (gl_TIME_R): Don't define HAVE_TIME_R_POSIX; no longer needed. Set REPLACE_LOCALTIME. * m4/timegm.m4 (gl_FUNC_TIMEGM): Set REPLACE_TIMEGM. * m4/timespec.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Move to time_h.m4. (gl_TIMESPEC): Don't check for sys/time.h or struct timespec or nanosleep; time_h.m4 now does that. Don't require gl_USE_SYSTEM_EXTENSIONS; no longer needed directly, and the time module handles this now. * modules/getdate (Depends-on): Remove timespec. Add time. * modules/nanosleep (Depends-on): Likewise. * modules/stat-time (Depends-on): Likewise. * modules/nanosleep (Include): Include time.h, not timespec.h. * modules/strptime (Files): Remove lib/strptime.h. (Depends-on): Add extensions, time. (Include): Include time.h, not strptime.h. * modules/time_r (Files): Remove lib/time_r.h. (Depends-on): Add time. (Include): Include time.h, not time_r.h. * modules/timegm: Likewise. * modules/timespec (Description): Now does timespec-related decls of our own, instead of struct timespec itself. (Depends-on): Add time; remove extensions. (Maintainer): Add self. * modules/utimecmp (Depends-on): Add time; remove timespec. * modules/utimens (Depends-on): Likewise. * modules/xnanosleep (Depends-on): Likewise.
Karl Berry 26bdd04d 2006-09-11T12:56:50 autoupdate
Paul Eggert 3ad2f5c4 2006-09-08T22:48:25 * config/srclist.txt: Temporarily comment out mktime.c until glibc bug 2821 is fixed. * lib/mktime.c (guess_time_tm): Fix bug where mktime returned the maximum time_t value rather than (time_t) -1. Problem originally reported by William Bardwell <http://sourceware.org/bugzilla/show_bug.cgi?id=2821>. * m4/mktime.m4 (AC_FUNC_MKTIME): Sync from Autoconf. Check for unistd.h too, since Autoconf doesn't assume POSIX. Also: 2006-09-08 Paul Eggert <eggert@cs.ucla.edu> Add year_2050_test to catch glibc bug 2821 <http://sourceware.org/bugzilla/show_bug.cgi?id=2821>. 2006-08-15 Paul Eggert <eggert@cs.ucla.edu> Prefer #ifdef to #if. 2006-04-02 Paul Eggert <eggert@cs.ucla.edu> Return from 'main' instead of calling 'exit'.
Karl Berry 69d12657 2005-09-18T12:30:04 srclist.update
Paul Eggert bf982dc2 2005-06-23T07:14:09 * mktime.c: Include <string.h> even if !DEBUG. (From glibc.) (ranged_convert): Don't save conversion in a temporary struct. This causes a warning with GCC 4.0.0, and anyway in the typical case it's not worth the extra 100 bytes or so of code. (ranged_convert, __mktime_internal): When calling a function via a pointer P, use P () rather than (*P) (), as we now assume C89 or better.
Paul Eggert 267a39ba 2005-05-14T06:03:57 *** empty log message ***
Paul Eggert 8d007e5a 2005-03-26T18:08:56 Propagate intprops.h comment fixes to mktime.c and strftime.c.
Paul Eggert f77aebf8 2005-03-15T00:39:17 * mktime.c (TYPE_TWOS_COMPLEMENT, TYPE_ONES_COMPLEMENT, TYPE_SIGNED_MAGNITUDE, TYPE_MINIMUM, TYPE_MAXIMUM): Sync from intprops.h. * strtol.c: Likewise.
Paul Eggert eef56b54 2005-03-09T19:11:23 Factor int-properties macros into a single file, except for glibc-related files. * lib/intprops.h: New file. * lib/getloadavg.c: Include it instead of limits.h. (INT_STRLEN_BOUND): Remove. * lib/human.c: Include intprops.h. (group_number): Use INT_STRLEN_BOUND instead of rolling it ourself. * lib/human.h (LONGEST_HUMAN_READABLE): Use 146/485 rather than 302/1000. * lib/inttostr.h: Include intprops.h instead of limits.h. (INT_STRLEN_BOUND, INT_BUFSIZE_BOUND): Remove. * lib/mktime.c (TYPE_IS_INTEGER, TYPE_TWOS_COMPLEMENT): New macros, for consistency with intprops.h. (time_t_is_integer, twos_complement_arithmetic): Use them. * lib/sig2str.h: Include <signal.h>, intprops.h. (INT_STRLEN_BOUND): Remove. * lib/strftime.c (TYPE_SIGNED): Remove. (INT_STRLEN_BOUND): Switch to same implementation as intprops.h. * lib/strtol.c: Adjust comments to match intprops.h. * lib/userspec.c: Include intprops.h. (TYPE_SIGNED, TYPE_MINIMUM, TYPE_MAXIMUM): Remove. * lib/utimecmp.c, lib/xnanosleep.c, lib/xstrtol.c: Likewise. * lib/utimecmp.c (utimecmp): Use TYPE_IS_INTEGER, TYPE_TWOS_COMPLEMENT instead of rolling our own expressions. * lib/xstrtol.c: Include xstrtol.h first, to test interface. * modules/getloadavg (Files): Add lib/intprops.h. * modules/human (Files): Likewise. * modules/inttostr (Files): Likewise. * modules/sig2str (Files): Likewise. * modules/userspec (Files): Likewise. * modules/utimecmp (Files): Likewise. * modules/xnanosleep (Files): Likewise. * modules/xstrtol (Files): Likewise.
Karl Berry 34d76dfe 2005-03-08T13:25:38 autoupdate
Paul Eggert cb48a016 2004-12-03T06:35:31 (__mktime_internal): If SEC_REQUESTED != SEC, convert T2, not T. (Imported from libc.)
Paul Eggert bdf8a3ff 2004-11-11T04:37:32 (SHR): New macro, which is a portable substitute for >> that should work even on Crays. (TIME_T_MIDPOINT, ydhms_diff, __mktime_internal): Use it. Problem reported by Mark D. Baushke in <http://lists.gnu.org/archive/html/bug-gnulib/2004-11/msg00071.html>.
Paul Eggert d5f3781d 2004-10-27T21:48:17 (not_equal_tm): Remove redundant check.
Paul Eggert ba17a19d 2004-10-22T20:19:01 (leapyear): Arg is long int, not int.
Jim Meyering d95c6009 2004-01-21T22:10:43 (__mktime_internal) [!_LIBC]: Define to mktime_internal so as not to conflict with a different-sized __mktime_internal function in GNU libc.
Paul Eggert 8b2c2981 2003-09-09T22:41:13 Remove K&R cruft.
Paul Eggert 7b224479 2003-09-06T21:34:07 Add time_r module. Change timegm, mktime, and strftime to use localtime_r and gmtime_r, now supplied by the time_r module. This fixes some timegm bugs and cleans up mktime and strftime a bit.
Paul Eggert c80984f8 2003-07-07T23:11:52 Fix some boundary cases and remove need for floating point. Issue a compile-time diagnostic if time_t is floating point, or if two's complement arithmetic is not in effect, or if arithmetic right shift does not propagate the sign. These assumptions were all in the original code but they weren't checked. (TIME_T_MIDPOINT, verify): New macros. (__isleap): Remove; it has integer overflow problems. (leapyear): New function, without those problems. (ydhms_tm_diff): Remove; splitting into two parts. (ydhms_diff): New function, containing the arithmetic part of the old ydhms_tm_diff function. Issue a compile-time diagnostic if we are not using C99 integer division. Avoid casts when possible. (guess_time_tm): New function, containing the checking part of the old ydhms_tm_diff function. Return the new value, rather than the difference between it and the old. Accept a new argument T so that *T specifies the old value. Check for overflow in the result. (__mktime_internal): Use a time_t offset, not a long int offset. This undoes the 2003-06-04 change, which is no longer needed now that we have better overflow checking. (localtime_offset): Likewise. (__mktime_internal): Avoid harmful overflow on hosts where time_t and long are 64-bit but int is only 32-bit. (ydhms_diff): Use long int to store year1 and yday1. Issue a compile-time diagnostic if long int is not wide enough. (__mktime_internal): Use long int to store adjusted year and yday. Use plain C rather than preprocessor commands, if that doesn't affect efficiency. Check for overflow (and try to repair) after each probe rather than checking only at the very end. This avoids some bugs (e.g., southern hemisphere, behind GMT, and GMT offset at minimum time does not equal GMT offset at maximum time). Use integer to check for overflow rather than floating point; this is more portable to non-IEEE hosts, and is a tad faster. When we detect that we are oscillating between two values, don't check whether tm_isdst has the requested value, since we already know the answer. When tm_isdst has the wrong value, use a different heuristic to find the right one, based on the extreme values actually observed in practice in tz2003a, rather than the (overly optimistic) "previous 3 calendar quarters". (not_equal_tm, print_tm, check_result): Use "const T" rather than "T const" to accommodate glibc style. (check_result): Use less-confusing report format. "long" -> "long int. (main): Likewise. Don't loop if the iteration overflows time_t. Allow a negative step in the iteration.
Paul Eggert bea5a055 2003-06-05T20:07:59 Assume freestanding C89 or better. (HAVE_LIMITS_H): Remove. Assume it's 1. (__P): Remove; not used. (INT_MIN, INT_MAX): Remove; <limits.h> defines them. (mktime, not_equal_tm, print_tm, check_result, main): Use prototypes. Use const * where appropriate. (main): Fix typo in testing code that uncovered by above changes.
Paul Eggert b2c42615 2003-06-05T06:43:15 Fix Debian bug 177940 <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=177940>. (localtime_offset): Now long int, not time_t, because we want it to be guaranteed to be signed. All uses changed. (__mktime_internal): If overflow would occur when adding offset, don't add it.
Paul Eggert a76a349e 2003-06-04T20:09:47 Ensure we use gnulib mktime rather than glibc's mktime, on hosts where mktime isn't the inverse of localtime (negative time_t).
Karl Berry 54a64110 2003-05-30T15:06:41 mktime update from libc
Paul Eggert 3b59684c 2003-05-28T20:18:22 (__mktime_internal): Do not reject negative timestamps arbitrarily.
Jim Meyering 41d8937a 2002-11-25T15:31:05 Really sync with libc, not with my locally-modified copy. Thanks, Karl!
Jim Meyering 1bc47090 2002-11-25T13:22:20 Sync from libc, now that it has the latest fix.
Jim Meyering fd8e762e 2002-11-24T10:39:54 Merge in changes from libc.
Jim Meyering 9d7d2eaf 2002-11-24T10:06:16 Avoid a link-time failure on some Linux systems. (STATIC): Define to be empty (_LIBC) or `static' (otherwise). (__mon_yday): Declare with the STATIC attribute. (__mktime_internal): Likewise.
Jim Meyering 89f2b489 2000-08-07T15:48:18 back out Copyright date changes for files with no changes year
Jim Meyering d349992d 2000-07-09T07:22:43 update copyright date
Jim Meyering b0aca2f6 1999-02-17T14:58:41 tweak comment
Jim Meyering f979eb04 1999-02-16T21:35:48 new version from Uli
Jim Meyering 7f20e762 1999-01-19T04:47:24 (__mktime_internal): Adopt the traditional (and problematic) notion of what to do when tm_isdst doesn't match. From Paul Eggert.
Jim Meyering cf42d3e5 1998-12-07T03:12:10 ansideclify
Jim Meyering d37eda27 1998-10-18T14:08:35 Don't invoke localtime_r or gmtime_r unless it's the GNU C library's localtime_r and gmtime_r; there are too many buggy implementations of localtime_r and gmtime_r out there, and it's not worth keeping track of all the different bugs. * mktime.c (__EXTENSIONS__, HAVE_LOCALTIME_R): Remove. (my_mktime_localtime_r): Renamed from localtime_r; all uses changed. Base it on localtime unless _LIBC.
Jim Meyering 6579bcf6 1998-10-18T01:10:21 Declare localtime_r if necessary.
Jim Meyering 184e8608 1998-10-17T12:39:30 Some systems require <unistd.h> to be included before <time.h> for localtime_r to be declared properly.
Jim Meyering 599729fb 1998-10-12T02:00:59 (_REENTRANT): Define again -- linux-2.0.33 needs it.
Jim Meyering a5382999 1998-10-11T23:03:41 (__mktime_internal): When the requested time falls in a spring-forward gap of size DT, return a time that is DT away from the requested time, preferring a time whose tm_isdst differs from the requested value. Bump the max number of probes from 4 to 6 to account for the extra probes needed to discover a spring-forward gap in the worst case.
Jim Meyering c5da3fd9 1998-10-08T12:19:48 (my_mktime_localtime_r): Renamed from localtime_r. Define also if HAVE_LOCALTIME_R && defined (localtime_r), with a body that merely expands localtime_r; this works around a bug in Digital Unix 4.0A and 4.0D.
Jim Meyering 0eeff3be 1998-04-12T15:16:37 .
Jim Meyering 96462d30 1998-04-12T09:39:30 (TYPE_MAXIMUM): Update from system.h.
Jim Meyering 9300fc8b 1998-02-24T23:19:13 add comment
Jim Meyering bfd921d6 1998-01-23T22:02:54 (__mktime_internal): Work around bug in Irix4.0.5's C compiler. From Kaveh Ghazi. (TYPE_MINIMUM): Define. (TYPE_MAXIMUM): Define. (TIME_T_MIN): Use TYPE_MINIMUM. (TIME_T_MAX): Use TYPE_MAXIMUM.
Jim Meyering fd396561 1997-11-18T03:32:00 (_REENTRANT): #define, as some hosts need this to declare localtime_r properly. From Paul Eggert.
Jim Meyering 1873f591 1997-11-13T13:22:54 Update from FSF.
Jim Meyering 89b2adc0 1997-09-17T12:46:45 update from FSF .../copies
Jim Meyering 068f1a3a 1997-03-14T03:28:09 (TIME_T_MIN): Work around a bug in Cray C 5.0.3.0.
Jim Meyering 77d822a7 1997-02-21T02:16:54 update from FSF
Jim Meyering 1631b5c0 1996-11-05T04:22:40 Fix copyright.
Jim Meyering 6d8337bf 1996-07-15T03:36:16 update FSF address in copyright
Jim Meyering 870b659d 1995-11-03T19:56:08 New version from glibc.
Jim Meyering 2c5d56e2 1994-09-27T22:02:08 merge with 1.10n2
Jim Meyering c9aad3a0 1994-08-19T22:42:32 merge with 1.10g
Jim Meyering 8965f456 1994-07-26T04:06:26 merge with 1.10f
Jim Meyering 6a75c0b2 1994-02-12T17:23:51 merge with 1.9.2i
Jim Meyering 43e78b97 1992-11-01T05:44:30 Initial revision