Local timegm() is a replacement function in cases it is missing from libc
implementation. Hopefully the replacement is never, or very rarely, used.
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
strnlen \
sysconf \
sysinfo \
+ timegm \
usleep \
warn \
warnx \
int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, size_t bufsz);
+#ifndef HAVE_TIMEGM
+extern time_t timegm(struct tm *tm);
+#endif
+
#endif /* UTIL_LINUX_TIME_UTIL_H */
#include <assert.h>
#include <ctype.h>
+#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
return rc <= 0 ? -1 : 0;
}
+#ifndef HAVE_TIMEGM
+time_t timegm(struct tm *tm)
+{
+ const char *zone = getenv("TZ");
+ time_t ret;
+
+ setenv("TZ", "", 1);
+ tzset();
+ ret = mktime(tm);
+ if (zone)
+ setenv("TZ", zone, 1);
+ else
+ unsetenv("TZ");
+ tzset();
+ return ret;
+}
+#endif /* HAVE_TIMEGM */
+
#ifdef TEST_PROGRAM_TIMEUTILS
int main(int argc, char *argv[])
#include "timeutils.h"
#include "xalloc.h"
#include "closestream.h"
+#include "timeutils.h"
static time_t strtotime(const char *s_time)
{