[PATCH v2 2/2] timegm.3: Remove recommendation against use of timegm()
Paul Eggert
eggert@cs.ucla.edu
Mon Oct 11 15:40:28 GMT 2021
On 10/11/21 4:12 AM, Alejandro Colomar wrote:
> time_t portable_timegm(struct tm *tm)
> {
> tm->tm_isdst = 0;
> /*
> * If another thread modifies the timezone during the
> * execution of the line below, it will produce undefined
> * behavior.
> */
> return mktime(tm) - timezone;
> }
This doesn't work for multiple reasons: it's not thread-safe, mktime
might set timezone even in a single-threaded app, and the subtraction
might overflow.
More information about the Libc-alpha
mailing list