[tz] Possible clarification to the tzalloc() documentation

Guy Harris gharris at sonic.net
Fri Jan 5 00:32:21 UTC 2024


The newtzset.3 man page says

       The tzalloc function allocates and returns a timezone object described
       by TZ. If TZ is not a valid timezone description, or if the object
       cannot be allocated, tzalloc returns a null pointer and sets errno.

This doesn't explicitly say that TZ == NULL amounts to "not a valid timezone description", nor does it explicitly say that implementation-defined default timezone information is used.  (The latter is the behavior the code implements.)

It does say

       If TZ is null, the best available approximation to local (wall clock)
       time, as specified by the tzfile(5)-format file localtime in the system
       time conversion information directory, is used.  If TZ is the empty
       string, UT is used, with the abbreviation "UTC" and without leap second
       correction; please see newctime(3) for more about UT, UTC, and leap
       seconds.  If TZ is nonnull and nonempty:

              if the value begins with a colon, it is used as a pathname of a
              file from which to read the time conversion information;

              if the value does not begin with a colon, it is first used as
              the pathname of a file from which to read the time conversion
              information, and, if that file cannot be read, is used directly
              as a specification of the time conversion information.

after describing taser:

       The tzset function acts like tzalloc(getenv("TZ")), except it saves any
       resulting timezone object into internal storage that is accessed by
       localtime, localtime_r, and mktime. The anonymous shared timezone
       object is freed by the next call to tzset. If the implied call to
       tzalloc fails, tzset falls back on Universal Time (UT).

but it might be clearer if the paragraph about tzset followed the "If TZ is..." text.

Perhaps the "If TZ is not a valid timezone description, or..." text should immediacy follow the "If TZ is..." text, e.g.

       The tzalloc function allocates and returns a timezone object described
       by TZ.

       If TZ is null, the best available approximation to local (wall clock)
       time, as specified by the tzfile(5)-format file localtime in the system
       time conversion information directory, is used.  If TZ is the empty
       string, UT is used, with the abbreviation "UTC" and without leap second
       correction; please see newctime(3) for more about UT, UTC, and leap
       seconds.  If TZ is nonnull and nonempty:

              if the value begins with a colon, it is used as a pathname of a
              file from which to read the time conversion information;

              if the value does not begin with a colon, it is first used as
              the pathname of a file from which to read the time conversion
              information, and, if that file cannot be read, is used directly
              as a specification of the time conversion information.  In the
              latter case, if TZ is not a valid timezone description, tzalloc
              returns a null pointer and sets errno.

       If the object cannot be allocated, or if a file cannot be read, tzalloc
       returns a null pointer and sets errno.

       The tzset function acts like tzalloc(getenv("TZ")), except it saves any
       resulting timezone object into internal storage that is accessed by
       localtime, localtime_r, and mktime. The anonymous shared timezone
       object is freed by the next call to tzset. If the implied call to
       tzalloc fails, tzset falls back on Universal Time (UT).

with, if necessary, text reminding people that, if TZ is not seen in the environment, tzalloc(getenv("TZ")) is equivalent to tzalloc(NULL), so "the best available approximation to local (wall clock) time..." is used.


More information about the tz mailing list