diff options
author | Sami Kerola | 2016-07-12 23:21:10 +0200 |
---|---|---|
committer | Sami Kerola | 2017-02-03 23:31:18 +0100 |
commit | b72a75e993d60d50cb9ed067aaf83197b3b1c9e1 (patch) | |
tree | f02324bcf2a47c22d6e6cf3a41c484a833589586 /lib/timeutils.c | |
parent | hwclock: remove UTC-0 localization hack (diff) | |
download | kernel-qcow2-util-linux-b72a75e993d60d50cb9ed067aaf83197b3b1c9e1.tar.gz kernel-qcow2-util-linux-b72a75e993d60d50cb9ed067aaf83197b3b1c9e1.tar.xz kernel-qcow2-util-linux-b72a75e993d60d50cb9ed067aaf83197b3b1c9e1.zip |
lib: add timegm() portability function to lib/timeutils.c
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>
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r-- | lib/timeutils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c index ea5c0aad8..d38970c10 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -20,6 +20,7 @@ #include <assert.h> #include <ctype.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <sys/time.h> @@ -460,6 +461,24 @@ int strtime_short(const time_t *t, struct timeval *now, int flags, char *buf, si 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[]) |