]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Implement utc_mktime() with timegm() if it exists.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 18 Apr 2016 13:40:49 +0000 (16:40 +0300)
committerGitLab <gitlab@git.dovecot.net>
Tue, 19 Apr 2016 15:48:21 +0000 (18:48 +0300)
It should be more efficient than repeatedly calling gmtime() many times.

configure.ac
src/lib/utc-mktime.c

index 095ceecac38f586045db082971f9d3f789d0441a..0dc61608e45040e5e4dfcd4dd41bc8239db0fd8c 100644 (file)
@@ -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 <sys/types.h>
index 89522579bc3d303f3f3ac7710cf807273c41dc71..566cb44dc26d9766ef2c14da5f4a1566068f9148 100644 (file)
@@ -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