From: Timo Sirainen Date: Mon, 18 Apr 2016 13:40:49 +0000 (+0300) Subject: lib: Implement utc_mktime() with timegm() if it exists. X-Git-Tag: 2.3.0.rc1~4010 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5a3e4396b53591bf1f22a73f9ec1a022f2c1e46;p=thirdparty%2Fdovecot%2Fcore.git lib: Implement utc_mktime() with timegm() if it exists. It should be more efficient than repeatedly calling gmtime() many times. --- diff --git a/configure.ac b/configure.ac index 095ceecac3..0dc61608e4 100644 --- a/configure.ac +++ b/configure.ac @@ -456,7 +456,7 @@ AC_CHECK_FUNCS(fcntl flock lockf inet_aton sigaction getpagesize madvise \ getmntinfo setpriority quotactl getmntent kqueue kevent \ backtrace_symbols walkcontext dirfd clearenv \ malloc_usable_size glob fallocate posix_fadvise \ - getpeereid getpeerucred inotify_init) + getpeereid getpeerucred inotify_init timegm) AC_CHECK_TYPES([struct sockpeercred],,,[ #include diff --git a/src/lib/utc-mktime.c b/src/lib/utc-mktime.c index 89522579bc..566cb44dc2 100644 --- a/src/lib/utc-mktime.c +++ b/src/lib/utc-mktime.c @@ -20,6 +20,18 @@ static int tm_cmp(const struct tm *tm1, const struct tm *tm2) return tm1->tm_sec - tm2->tm_sec; } +#ifdef HAVE_TIMEGM +time_t utc_mktime(const struct tm *tm) +{ + struct tm mod_tm = *tm; + time_t t; + + t = timegm(&mod_tm); + if (tm_cmp(tm, &mod_tm) != 0) + return (time_t)-1; + return t; +} +#else time_t utc_mktime(const struct tm *tm) { const struct tm *try_tm; @@ -51,3 +63,4 @@ time_t utc_mktime(const struct tm *tm) return (time_t)-1; } +#endif