[PATCH] add tests for tzset(3)

jdoubleu hi@jdoubleu.de
Fri Apr 15 10:10:06 GMT 2022


On Thu, Apr 14, 2022 at 12:31 PM Brian Inglis wrote:
> I am still not hearing from where the requirement originates to set
> UTC/GMT/etc or do anything other than leave everything as is.
> Is this glibc behaviour, and why not /etc/localtime or /etc/timezone?

On 4/14/2022 9:23 PM, Jeff Johnston wrote:
> It is glibc behaviour as I mentioned in my note. The following is also
> from man tzset

Aside from glibc, the BSD man page[1] also states:
> If the TZ environment variable [..] cannot be interpreted as a direct specification, UTC is used.
Where "direct specification" is the formatted string.

The POSIX standard does not seem to explicitly state what happens in an 
error case, besides[2]:
> The interpretation of these fields is unspecified if either field is less than three bytes [..],  > more than {TZNAME_MAX} bytes, or if they contain characters other 
than those specified.and[3]
> If TZ is absent from the environment, implementation-defined default timezone information shall be used.

[1]: https://man.openbsd.org/tzset
[2]: 
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
[2]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/tzset.html#


Cheers
---
🙎🏻‍♂️ jdoubleu
On 4/14/2022 9:23 PM, Jeff Johnston wrote:
> On Thu, Apr 14, 2022 at 12:31 PM Brian Inglis <
> Brian.Inglis@systematicsw.ab.ca> wrote:
> 
>> I am still not hearing from where the requirement originates to set
>> UTC/GMT/etc or do anything other than leave everything as is.
>> Is this glibc behaviour, and why not /etc/localtime or /etc/timezone?
>>
>>
> It is glibc behaviour as I mentioned in my note.  The following is also
> from man tzset
> 
>        If the TZ variable does not appear in the environment, the tzname
> vari‐
>         able  is  initialized  with  the best approximation of local wall
> clock
>         time, as specified by the tzfile(5)-format file localtime found in
>   the
>         system   timezone   directory   (see  below).   (One  also  often
>   sees
>         /etc/localtime used here, a symlink to the right  file  in  the
>   system
>         timezone directory.)
> 
>         If  the  TZ  variable  does  appear in the environment but its value
> is
>         empty or its value cannot be interpreted using any of the formats
> spec‐
>         ified below, Coordinated Universal Time (UTC) is used.
> 
> Note about if its value is specified and cannot be interpreted using any of
> the formats specified.
> If there is an error, then that clause would apply.  In glibc's case, it is
> less than 3 chars and invalid
> chars.  In our case, exceeding the max limit would also apply.
> 
>  From glibc: tzset.c
> 
>   /* Clear out old state and reset to unnamed UTC.  */
>    memset (tz_rules, '\0', sizeof tz_rules);
>    tz_rules[0].name = tz_rules[1].name = "";
> 
>    /* Get the standard timezone name.  */
>    if (parse_tzname (&tz, 0) && parse_offset (&tz, 0))
> 
> If the parse_tzname fails or parsing the dst name fails, unnamed UTC is
> used.
> 
> -- Jeff J.
> 


More information about the Newlib mailing list