]> Savannah Git Hosting - gnulib.git/commitdiff
timegm: ignore incoming tm_isdst
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 4 Oct 2024 16:12:42 +0000 (09:12 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 4 Oct 2024 16:16:25 +0000 (09:16 -0700)
Problem reported by Florian Weimer via a proposed glibc patch in:
https://sourceware.org/pipermail/libc-alpha/2024-October/160310.html
* lib/mktime.c (__mktime_internal): Ignore any tm_isdst request
if the timezone never observes DST, as is the case for timegm.
* m4/mktime.m4 (gl_PREREQ_MKTIME): Define new C macro __daylight
if needed.

ChangeLog
lib/mktime.c
m4/mktime.m4

index d8ec6067da0543f95f1e7e0fd04ddae716230b40..7a7f6dd78219251d943c7386011a5f579af64755 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-10-04  Paul Eggert  <eggert@cs.ucla.edu>
 
+       timegm: ignore incoming tm_isdst
+       Problem reported by Florian Weimer via a proposed glibc patch in:
+       https://sourceware.org/pipermail/libc-alpha/2024-October/160310.html
+       * lib/mktime.c (__mktime_internal): Ignore any tm_isdst request
+       if the timezone never observes DST, as is the case for timegm.
+       * m4/mktime.m4 (gl_PREREQ_MKTIME): Define new C macro __daylight
+       if needed.
+
        timegm: desync from glibc for now
        * config/srclist.txt: Omit time/timegm.c and time/mktime-internal.h
        for now, until we can sync glibc from Gnulib.
index 561c9487137e60b0944e5ef6b3ddcceab008ed78..67bfcb956f5398fe030a91bdc676fb9faecfe3fc 100644 (file)
@@ -339,7 +339,9 @@ __mktime_internal (struct tm *tp, bool local, mktime_offset_t *offset)
   int mday = tp->tm_mday;
   int mon = tp->tm_mon;
   int year_requested = tp->tm_year;
-  int isdst = tp->tm_isdst;
+
+  /* If the timezone never observes DST, ignore any tm_isdst request.  */
+  int isdst = local && __daylight ? tp->tm_isdst : 0;
 
   /* 1 if the previous probe was DST.  */
   int dst2 = 0;
index 85c52454aa5eaf9b4586bbb060b7c4e2d525602c..14ced571e06a87bcc04de394e9098e078c1bbc1b 100644 (file)
@@ -1,5 +1,5 @@
 # mktime.m4
-# serial 39
+# serial 40
 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -315,4 +315,22 @@ AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [
 ])
 
 # Prerequisites of lib/mktime.c.
-AC_DEFUN([gl_PREREQ_MKTIME], [:])
+AC_DEFUN([gl_PREREQ_MKTIME], [
+  AC_CACHE_CHECK([spelling of daylight variable],
+    [gl_cv_var___daylight],
+    [for gl_cv_var___daylight in __daylight daylight _daylight 0; do
+       test $gl_cv_var___daylight = 0 && break
+       AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <time.h>
+            ]],
+            [[return $gl_cv_var___daylight;]])
+         ],
+         [break])
+     done])
+  AS_CASE([$gl_cv_var___daylight],
+    [__daylight], [],
+    [AC_DEFINE_UNQUOTED([__daylight], [$gl_cv_var___daylight],
+       [Define to an expression equivalent to <time.h> daylight
+        if <time.h> __daylight does not already do that.])])
+])