#include <time.h> time_t timelocal(struct tm *tm); time_t timegm(struct tm *tm);glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
timelocal(), timegm(): _BSD_SOURCE || _SVID_SOURCE
timegm() を移植性があるようなかたちで実現するには、 TZ 環境変数を UTC に設定してから mktime(3) を呼んで、 TZ の値を取得すればよい。 例えば次のようになるだろう。
#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;
}