[PATCH 2/4] time: Push tzset lock into callers of time functions

Paul Eggert eggert@cs.ucla.edu
Tue Oct 1 17:35:58 GMT 2024


On 2024-10-01 05:14, Florian Weimer wrote:
> +#ifdef _LIBC
> +# include <tzset.h>
> +#endif
>   
>   #include <errno.h>
>   #include <limits.h>
> @@ -256,11 +259,15 @@ tm_diff (long_int year, long_int yday, int hour, int min, int sec,
>   static struct tm *
>   convert_time (bool local, long_int t, struct tm *tm)
>   {
> +#ifdef _LIBC
> +  return __tz_convert (t, local, tm);
> +#else
>     __time64_t x = t;
>     if (local)
>       return __localtime64_r (&x, tm);
>     else
>       return __gmtime64_r (&x, tm);
> +#endif

Come to think of it, the !_LIBC code needn't fiddle with types like 
__time64_t or symbols like __localtime64_r because they're not relevant 
in Gnulib.

Please migrate the "#ifdef _LIBC" stuff higher, e.g., something like 
this near the top.:

   #ifdef _LIBC
   # include <tzset.h>
   #else
   static struct tm *
   __tz_convert (time_t t, bool local, struct tm *tm)
   {
      return (local ? localtime_r : gmtime_r) (&t, tm);
   }
   #endif

and then change the rest of the file to use __tz_convert instead of 
convert_time. That way, we can remove convert_time and the glibc code 
will be more uniform about calling __tz_convert.


More information about the Libc-alpha mailing list