79686636

Date: 2025-07-01 21:56:18
Score: 0.5
Natty:
Report link

timegm() is a non-standard GNU extension. A portable version using mktime() is below. This sets the TZ environment variable to UTC, calls mktime() and restores the value of TZ. Since TZ is modified this might not be thread safe. I understand the GNU libc version of tzset() does use a mutex so should be thread safe.

See:

#include <time.h>
#include <stdlib.h>

time_t
my_timegm(struct tm *tm)
{
    time_t ret;
    char *tz;

   tz = getenv("TZ");
    setenv("TZ", "", 1);
    tzset();
    ret = mktime(tm);
    if (tz)
        setenv("TZ", tz, 1);
    else
        unsetenv("TZ");
    tzset();
    return ret;
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): is a
  • Low reputation (1):
Posted by: iandiver