> On Jul 20, 2026, at 7:57 PM, Paul Gilmartin via tz <[email protected]> wrote:
> 
> On 7/20/26 16:20, Steffen Nurpmeso wrote:
>> Paul Eggert via tz wrote in
>>       ...
>>  |tzcode provides a way: if tzalloc("ABC") returns a null pointer and
>>  |errno has a value other than ENOMEM, then "ABC" is invalid. So if you're
>>  |on platforms like NetBSD that have tzalloc, you have a way. Or you can
>>  |copy tzcode and use its tzalloc.
>>  
> This appears to be a thread-safe replacement
> for localtime().  I need to RTFM more.

localtime_r() already serves as a thread-safe replacement for localtime() in 
most cases.

However:

> o localtime() should have a time_t argument.

localtime() does have a time_t argument, and the time argument to localtime_r() 
is also a time_t.

The same applies to the time argument to localtime_rz() 
(https://man.netbsd.org/localtime_rz.3).

> I see no such for tzalloc().

This is for the case where localtime_r() is *not* sufficient as a thread-safe 
replacement for localtime()...

...i.e., the case where different threads want to convert a time_t to local 
time in some *arbitrary* timezone, with the timezone being thread-specific. 
Tweaking the TZ environment variable (if possible, e.g. using setenv()) isn't 
thread-safe.

> o strftime() needs a struct tm argument. Does tzalloc() generate one?

No.

tzalloc(), as Paul Eggert noted, takes a string argument containing a tzid and 
return s pointer to an object that represents the timezone corresponding to 
that tzid. It can be used in localtime_rz() calls to convert a time_t value to 
a struct tm value for the local time that the time_t represents in that 
timezone, passed to ctime_rz() to convert a time_t value to a string for the 
local time that the time_t represents in that timezone, and to mltime_z() to 
convert a struct tm to the time_t that it represents in that timezone.

tzfree() frees the object in question.

Reply via email to