aboutsummaryrefslogtreecommitdiff
path: root/time/mktime.c
AgeCommit message (Collapse)AuthorFilesLines
2024-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
2023-06-22Call "CST" a time zone abbreviation, not a namePaul Eggert1-1/+1
In documentation, call strings like "CST" time zone abbreviations, not time zone names. This terminology is more precise, and is what tzdb uses. A string like "CST" is ambiguous and does not fully name a time zone.
2023-01-06Update copyright dates with scripts/update-copyrightsJoseph Myers1-1/+1
2022-09-08mktime: improve heuristic for ca-1986 Indiana DSTPaul Eggert1-8/+20
This patch syncs mktime.c from Gnulib, fixing a problem reported by Mark Krenz <https://bugs.gnu.org/48085>, and it should fix BZ#29035 too. * time/mktime.c (__mktime_internal): Be more generous about accepting arguments with the wrong value of tm_isdst, by falling back to a one-hour DST difference if we find no nearby DST that is unusual. This fixes a problem where "1986-04-28 00:00 EDT" was rejected when TZ="America/Indianapolis" because the nearest DST timestamp occurred in 1970, a temporal distance too great for the old heuristic. This also also narrows the search a bit, which is a minor performance win.
2022-09-08Assume HAVE_TZSET in time/mktime.cPaul Eggert1-1/+1
This patch does not affect glibc. It affects only Gnulib-specific code and is for coordination with Gnulib.
2022-01-01Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 7061 files FOO. I then removed trailing white space from math/tgmath.h, support/tst-support-open-dev-null-range.c, and sysdeps/x86_64/multiarch/strlen-vec.S, to work around the following obscure pre-commit check failure diagnostics from Savannah. I don't know why I run into these diagnostics whereas others evidently do not. remote: *** 912-#endif remote: *** 913: remote: *** 914- remote: *** error: lines with trailing whitespace found ... remote: *** error: sysdeps/unix/sysv/linux/statx_cp.c: trailing lines
2021-01-02Update copyright dates with scripts/update-copyrightsPaul Eggert1-1/+1
I used these shell commands: ../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright (cd ../glibc && git commit -am"[this commit message]") and then ignored the output, which consisted lines saying "FOO: warning: copyright statement not found" for each of 6694 files FOO. I then removed trailing white space from benchtests/bench-pthread-locks.c and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this diagnostic from Savannah: remote: *** pre-commit check failed ... remote: *** error: lines with trailing whitespace found remote: error: hook declined to update refs/heads/master
2020-08-04Sync mktime.c from GnulibPaul Eggert1-3/+3
* time/mktime.c: Sync from Gnulib. This micro-optimizes three division-related computations.
2020-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2019-10-31Sync time/mktime.c with gnulibPaul Eggert1-1/+1
This syncs with gnulib commit 9e78024bad107fe786cc3e5e328a475921ea0873. * time/mktime.c: Update URL in comment.
2019-04-30Make mktime etc. compatible with __time64_tPaul Eggert1-27/+44
Keep these functions compatible with Gnulib while adding __time64_t support. The basic idea is to move private API declarations from include/time.h to time/mktime-internal.h, since the former file cannot easily be shared with Gnulib whereas the latter can. Also, do some other minor cleanup while in the neighborhood. * include/time.h: Include stdbool.h, time/mktime-internal.h. (__mktime_internal): Move this prototype to time/mktime-internal.h, since Gnulib needs it. (__localtime64_r, __gmtime64_r) [__TIMESIZE == 64]: Move these macros to time/mktime-internal.h, since Gnulib needs them. (__mktime64, __timegm64) [__TIMESIZE != 64]: New prototypes. (in_time_t_range): New static function. * posix/bits/types.h (__time64_t) [__TIMESIZE == 64 && !defined __LIBC]: Do not define as a macro in this case, so that portable code is less tempted to use __time64_t. * time/mktime-internal.h: Rewrite so that it does both glibc and Gnulib work. Include time.h if not _LIBC. (mktime_offset_t) [!_LIBC]: Define for gnulib. (__time64_t, __gmtime64_r, __localtime64_r, __mktime64, __timegm64) [!_LIBC || __TIMESIZE == 64]: New macros, mostly moved here from include/time.h. (__gmtime_r, __localtime_r, __mktime_internal) [!_LIBC]: New macros, taken from GNulib. (__mktime_internal): New prototype, moved here from include/time.h. * time/mktime.c (mktime_min, mktime_max, convert_time) (ranged_convert, __mktime_internal, __mktime64): * time/timegm.c (__timegm64): Use __time64_t, not time_t. * time/mktime.c: Stop worrying about whether time_t is floating-point. (__mktime64) [! (_LIBC && __TIMESIZE != 64)]: Rename from mktime. (mktime) [_LIBC && __TIMESIZE != 64]: New function. * time/timegm.c [!_LIBC]: Include libc-config.h, not config.h, for libc_hidden_def. Include errno.h. (__timegm64) [! (_LIBC && __TIMESIZE != 64)]: Rename from timegm. (timegm) [_LIBC && __TIMESIZE != 64]: New function. First cut at publicizing __time64_t
2019-03-17* time/mktime.c: Update obsolete URL in comment.Paul Eggert1-1/+1
2019-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
* All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
2018-11-15mktime: DEBUG_MKTIME cleanupPaul Eggert1-160/+2
The DEBUG_MKTIME code no longer works in glibc or in Gnulib. And it’s no longer needed now that glibc and Gnulib both have their own testing mechanisms for mktime. * time/mktime.c (DEBUG_MKTIME): Remove. All uses removed.
2018-11-15mktime: fix non-EOVERFLOW errno handlingPaul Eggert1-98/+99
[BZ#23789] mktime was not properly reporting failures when the underlying localtime_r fails with errno != EOVERFLOW; it incorrectly treated them like EOVERFLOW failures, and set errno to EOVERFLOW. The problem could happen on non-glibc platforms, with Gnulib. * time/mktime.c (guess_time_tm): Remove, replacing with ... (tm_diff): ... this simpler function, which does not change errno. All callers changed to deal with errno themselves. (ranged_convert, __mktime_internal): Return failure immediately if the underlying function reports any failure other than EOVERFLOW. (__mktime_internal): Set errno to EOVERFLOW if the spring-forward gap code fails.
2018-11-15mktime: fix bug with Y2038 DST transitionPaul Eggert1-1/+3
[BZ#23789] * time/mktime.c (ranged_convert): On 32-bit platforms, don’t mishandle a DST transition that jumps over the Y2038 boundary. No such DST transitions are known so this is only a theoretical bug, but we might as well do things right.
2018-11-15mktime: make more room for overflowPaul Eggert1-9/+11
[BZ#23789] * time/mktime.c (long_int): Now 4⨯ int, not just 3⨯. This is so that we can add tm_diff results to a previous guess, which will be useful in a later patch.
2018-11-15mktime: simplify offset guessPaul Eggert1-3/+3
[BZ#23789] * time/mktime.c (__mktime_internal): Omit excess precision.
2018-11-15mktime: fix EOVERFLOW bugPaul Eggert1-7/+19
[BZ#23789] * time/mktime.c [!_LIBC && !DEBUG_MKTIME]: Include libc-config.h, not config.h, for __set_errno. (guess_time_tm, __mktime_internal): Set errno to EOVERFLOW on overflow.
2018-10-08mktime fix for Gnulib + coreutilsPaul Eggert1-1/+1
[BZ#23745] This fix affects only Gnulib. Problem discovered when mktime.c was used as part of Gnulib in bleeding-edge Coreutils. * time/mktime.c: (my_tzset) [!_LIBC && !NEED_MKTIME_WORKING && !NEED_MKTIME_WINDOWS]: Do not define since it is not used. Defining an unused static function prompts a warning from GCC when Coreutils is configured with --enable-gcc-warnings.
2018-09-19Merge mktime, timegm from upstream GnulibPaul Eggert1-298/+247
[BZ #23603][BZ #16346] This fixes some obscure problems with integer overflow. Although it looks scary, it is almost all a byte-for-byte copy from Gnulib, and the Gnulib code has been tested reasonably well. * include/intprops.h: New file, copied from Gnulib. * include/verify.h, time/mktime-internal.h: New tiny files, simplified from Gnulib. * time/mktime.c: Copy from Gnulib. This has the following changes: Do not include config.h if DEBUG_MKTIME is nonzero. Include stdbool.h, intprops.h, verify.h. Include string.h only if needed. Include stdlib.h on MS-Windows. Include mktime-internal.h. (DEBUG_MKTIME): Default to 0, and simplify later uses. (NEED_MKTIME_INTERNAL, NEED_MKTIME_WINDOWS) (NEED_MKTIME_WORKING): Give default values to pacify -Wundef, which glibc uses. Default NEED_MKTIME_WORKING to DEBUG_MKTIME, to simplify later conditionals; default the others to zero. Use these conditionals to express only the code needed on the current platform. In uses of these conditionals, explicitly spell out how _LIBC affects things, so it’s easier to review from a glibc viewpoint. (WRAPV): Remove; no longer needed now that we have systematic overflow checking. (my_tzset, __tzset) [!_LIBC]: New function and macro, to better compartmentalize tzset issues. Move system-dependent tzsettish code here from mktime. (verify): Remove; now done by verify.h. All uses changed. (long_int): Use a more-conservative definition, to avoid integer overflow. (SHR): Remove, replacing with ... (shr): New function, which means we needn’t worry about side effects in args, and conversion analysis is simpler. (TYPE_IS_INTEGER, TYPE_TWOS_COMPLEMENT, TYPE_SIGNED, TYPE_MINIMUM) (TYPE_MAXIMUM, TIME_T_MIN, TIME_T_MAX, TIME_T_MIDPOINT) (time_t_avg, time_t_add_ok): Remove. (mktime_min, mktime_max): New constants. (leapyear, isdst_differ): Use bool for booleans. (ydhms_diff, guess_time_tm, ranged_convert, __mktime_internal): Use long_int, not time_t, for mktime differences. (long_int_avg): New function, replacing time_t_avg. INT_ADD_WRAPV replaces time_t_add_ok. (guess_time_tm): 6th arg is now long_int, not time_t const *. All uses changed. (convert_time): New function. (ranged_convert): Use it. (__mktime_internal): Last arg now points to mktime_offset_t, not time_t. All uses changed. This is a no-op on glibc, where mktime_offset_t is always time_t. Use int, not time_t, for UTC offset guess. Directly check for integer overflow instead of using a heuristic that works only 99.9...% of the time. Access *OFFSET only once, to avoid an unlikely race if the compiler delays a load and if this cascades into a signed integer overflow. (mktime): Move tzsettish code to my_tzset, and move localtime_offset to within mktime so that it doesn’t need a separate ifdef. (main) [DEBUG_MKTIME]: Speed up by using localtime_r instead of localtime. * time/timegm.c: Copy from Gnulib. This has the following changes: Include mktime-internal.h. [!_LIBC]: Include config.h and time.h. Do not include timegm.h or time_r.h. Make __mktime_internal a macro, and include mktime-internal.h to get its declaration. (timegm): Temporary is now mktime_offset_t, not time_t. This affects only Gnulib.
2018-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
* All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
2017-01-01Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2016-01-15Fix build failures with -DDEBUG.Martin Sebor1-6/+6
[BZ #19443] * crypt/crypt_util.c [DEBUG] (_ufc_prbits): Correct format string. [DEBUG] (_ufc_set_bits): Declare used. * iconv/gconv_dl.c [DEBUG]: Add a missing include directive. [DEBUG] (print_all): Declare used. * resolv/res_send.c [DEBUG] (__libc_res_nsend): Explicitly convert operands of the ternary ?: expression to target type. * stdlib/rshift.c [DEBUG] (mpn_rshift): Use assert() instead of calling the undeclared abort. * time/mktime.c [DEBUG] (DEBUG): Rename to DEBUG_MKTIME.
2016-01-04Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2015-01-02Update copyright dates with scripts/update-copyrights.Joseph Myers1-1/+1
2014-06-28Sync up mktime with gnulibPaul Eggert1-2/+2
From the gnulib commit log: commit e2646b0c6b5acda25e9ffeb4c12a5513a1e3b5ac Author: Paul Eggert <eggert@cs.ucla.edu> Date: Fri Jun 27 11:35:44 2014 -0700 mktime: merge #if/#ifdef usage from glibc * lib/mktime.c: Use "#if defined DEBUG && DEBUG", not "#if DEBUG", as that works with both Glibc's and Gnulib's style. See thread starting at Siddhesh Poyarekar's bug report at: http://lists.gnu.org/archive/html/bug-gnulib/2014-06/msg00102.html
2014-06-27Remove inline keyword from leapyear functionSiddhesh Poyarekar1-1/+1
This syncs up the code with gnulib.
2014-01-01Update copyright notices with scripts/update-copyrightsAllan McRae1-1/+1
2013-02-07Remove lots of inline keywords.Roland McGrath1-1/+1
2013-01-02Update copyright notices with scripts/update-copyrights.Joseph Myers1-1/+1
2012-05-23mktime: avoid signed integer overflowPaul Eggert1-4/+4
* time/mktime.c (__mktime_internal): Do not mishandle the case where diff == INT_MIN.
2012-05-23mktime: simplify computation of averagePaul Eggert1-3/+1
* time/mktime.c (ranged_convert): Use new time_t_avg function instead of rolling our own (probably-slower) code.
2012-05-23mktime: do not assume signed right shift propagates sign bitPaul Eggert1-6/+12
* time/mktime.c (isdst_differ): New static function. (__mktime_internal): No need to normalize tm_isdst now. (__mktime_internal, not_equal_tm): Use isdst_differ to compare tm_isdst values.
2012-05-23mktime: merge another wrapv change from gnulibPaul Eggert1-1/+1
* time/mktime.c (TYPE_MAXIMUM): Rework slightly to avoid diagnostics from some compilers.
2012-05-23mktime: remove incorrect attempt at unusual arithmeticsPaul Eggert1-9/+6
* time/mktime.c (TYPE_ONES_COMPLEMENT, TYPE_SIGNED_MAGNITUDE): Remove. The code didn't really work on such machines anyway. (TYPE_MINIMUM): Assume two's complement. (twos_complement_arithmetic): Verify that long_int and time_t are two's complement (or unsigned, in the latter case).
2012-05-23mktime: check signed shifts on long_int and time_t, tooPaul Eggert1-3/+5
* time/mktime.c (SHR): Check that shifts work as desired on the types long_int and time_t too, as SHR is used on such types.
2012-05-23mktime: do not assume 'long' is wide enoughPaul Eggert1-12/+18
* time/mktime.c (verify): Move decl up. (long_int): New type. (leapyear, ydhms_diff, guess_time_tm, __mktime_internal): Use it, to remove assumption in the code that 'long' is wide enough to store year values. This assumption is not true on x32 and on some non-glibc platforms.
2012-05-23mktime: merge wrapv change from gnulibPaul Eggert1-25/+90
* time/mktime.c (WRAPV): New macro. (time_t_avg, time_t_add_ok, time_t_int_add_ok): New static functions. (guess_time_tm, __mktime_internal): Do not assume that signed integer overflow wraps around; modern compilers generate code where this assumption is no longer valid.
2012-05-22Update copyright years for time/mktime.cH.J. Lu1-1/+1
2012-05-22mktime: merge comment-quoting-style change from gnulibPaul Eggert1-3/+3
2012-05-22time/mktime.c (compile-command): Add "-I."Paul Eggert1-1/+1
2012-05-22mktime: merge mktime-internal.h change from gnulibPaul Eggert1-0/+1
2012-05-22mktime: merge time_r change from gnulibPaul Eggert1-2/+1
2012-05-22mktime: merge DEBUG change from gnulibPaul Eggert1-0/+1
2012-05-22mktime: merge <sys/types.h> change from gnulibPaul Eggert1-1/+0
2012-05-22mktime: merge HAVE_CONFIG_H change from gnulibPaul Eggert1-1/+1
2012-02-09Replace FSF snail mail address with URLs.Paul Eggert1-3/+2
2008-07-06(__mktime_internal): Normalize tp->tm_isdst value.Ulrich Drepper1-2/+4
2007-12-12* time/bug-getdate1.c (do_test): Don't use century values whichUlrich Drepper1-2/+2
aren't valid on 32-bit systems.