On 2025-09-24 00:36, Robert Elz wrote:
If what is there is the same as in C89
It's not. C89 §4.12.3 "Time conversion functions" says, "Except for the strftime function, these functions return values in one of two static objects: a broken-down time structure and an array of char. Execution of any of the functions may overwrite the information returned in either of these objects by any of the other functions." And §4.12.3.2 says that ctime(x) is equivalent to asctime(localtime(timer)). This wording is intended to require the 7th Edition Unix behavior, where calling any of localtime, gmtime, and ctime overwrote the same struct tm object.
So in C89 it's crystal clear that successful calls to localtime and gmtime must return the same pointer. C23 makes it clear that the requirement is no longer present; C99 through C17 (and therefore POSIX.1-2001 through POSIX.1-2024) relax the C89 requirement to allow localtime and gmtime to use different objects, but using wording that you regard as so muddled that it allows some of the FreeBSD behavior. But even under your more relaxed interpretation, the FreeBSD behavior does not conform to POSIX versions through POSIX.1-2024, or to C89 through C17, because it sometimes frees storage addressed by the returned values of localtime and gmtime, something these standards do not allow.
Any library that wants to support old binaries that assume pre-POSIX.1-2001 behavior must have just one object for both gmtime and localtime. This 7th Edition Unix behavior conforms to all the standards, and portable programs should allow (though not insist on) this behavior.
