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.
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
#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
/* 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;
tzset ();
# endif
}
-# undef __tzset
-# define __tzset() my_tzset ()
+# undef tzset
+# define tzset() my_tzset ()
#endif
#if defined _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL
__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;
__time64_t result = mktime (tp);
# endif
-# ifdef _LIBC
__libc_lock_unlock (__tzset_lock);
-# endif
-
return result;
}
#endif /* _LIBC || NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS */