]> Savannah Git Hosting - gnulib.git/commitdiff
mktime: ease merge of locking code with glibc
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Jan 2025 05:08:29 +0000 (21:08 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Jan 2025 05:10:44 +0000 (21:10 -0800)
This shouldn't affect behavior of either Gnulib or glibc.
* lib/mktime-internal.h (__libc_lock_lock, __libc_lock_unlock)
(__tzset_unlocked) [!_LIBC]: New macros.
* lib/mktime.c (tzset) [!_LIBC]: Define this instead of __tzset,
if defining either.
(__mktime64): Simplify now that mktime-internal defines
libc-specific macros to noops when !_LIBC.

ChangeLog
lib/mktime-internal.h
lib/mktime.c

index 629f1b8d3f206421d2e38b18d09eea323169c81d..7870c91b3175baaeb5439714e3f6714bd61b5f1c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2025-01-04  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mktime: ease merge of locking code with glibc
+       This shouldn't affect behavior of either Gnulib or glibc.
+       * lib/mktime-internal.h (__libc_lock_lock, __libc_lock_unlock)
+       (__tzset_unlocked) [!_LIBC]: New macros.
+       * lib/mktime.c (tzset) [!_LIBC]: Define this instead of __tzset,
+       if defining either.
+       (__mktime64): Simplify now that mktime-internal defines
+       libc-specific macros to noops when !_LIBC.
+
        mktime: improve tm_isdst heuristic
        * lib/mktime.c (__mktime_internal): When tm_isdst disagrees with
        what was requested, search at most a year (+ stride) from the
index 1da98b43732391df0102ca34c09ad2a822e9751c..215be914c2f7e91668039190123b51ae8e5856b2 100644 (file)
@@ -19,6 +19,9 @@
 
 #ifndef _LIBC
 # include <time.h>
+# define __libc_lock_lock(lock) ((void) 0)
+# define __libc_lock_unlock(lock) ((void) 0)
+# define __tzset_unlocked() tzset ()
 #endif
 
 /* mktime_offset_t is a signed type wide enough to hold a UTC offset
@@ -73,6 +76,8 @@ typedef int mktime_offset_t;
 /* Subroutine of mktime.  Return the time_t representation of TP and
    normalize TP, given that a struct tm * maps to a time_t.  If
    LOCAL, the mapping is performed by localtime_r, otherwise by gmtime_r.
-   Record next guess for localtime-gmtime offset in *OFFSET.  */
+   Record next guess for localtime-gmtime offset in *OFFSET.
+
+   If _LIBC, the caller must lock __tzset_lock.  */
 extern __time64_t __mktime_internal (struct tm *tp, bool local,
                                      mktime_offset_t *offset) attribute_hidden;
index 4448a92c062cff933c90444493deb998cbd8bcd3..4218fca69b16e7b444b9ddfd1e0b53e997fbb867 100644 (file)
@@ -101,8 +101,8 @@ my_tzset (void)
   tzset ();
 # endif
 }
-# undef __tzset
-# define __tzset() my_tzset ()
+# undef tzset
+# define tzset() my_tzset ()
 #endif
 
 #if defined _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL
@@ -540,12 +540,8 @@ __mktime_internal (struct tm *tp, bool local, mktime_offset_t *offset)
 __time64_t
 __mktime64 (struct tm *tp)
 {
-# ifdef _LIBC
   __libc_lock_lock (__tzset_lock);
   __tzset_unlocked ();
-# else
-  __tzset ();
-# endif
 
 # if defined _LIBC || NEED_MKTIME_WORKING
   static mktime_offset_t localtime_offset;
@@ -555,10 +551,7 @@ __mktime64 (struct tm *tp)
   __time64_t result = mktime (tp);
 # endif
 
-# ifdef _LIBC
   __libc_lock_unlock (__tzset_lock);
-# endif
-
   return result;
 }
 #endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS */