From: Thibault Godouet Date: Fri, 12 Jun 2015 21:54:50 +0000 (+0100) Subject: added my_time() to use the more accurate (at least on recent Linux systems) gettimeof... X-Git-Tag: ver3_2_1~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eaceb20b834ecf0d4fddf214f91ad0ab352090a0;p=fcron added my_time() to use the more accurate (at least on recent Linux systems) gettimeofday() where it is available --- diff --git a/subs.c b/subs.c index bdae71f..69316f4 100644 --- a/subs.c +++ b/subs.c @@ -24,6 +24,7 @@ #include "global.h" #include "subs.h" +#include uid_t get_user_uid_safe(char *username) @@ -475,3 +476,20 @@ imin(int x, int y) return y; } } + +time_t +my_time(void) +/* return the current time as number of seconds since the Epoch. */ +{ + /* Use gettimeofday() if available as this is more accurate + * than time() on recent Linux systems. + * (I suspect time() sacrifies accuracy for speed in the same way as + * clock_gettime()'s CLOCK_REALTIME_COARSE, and only updates on systems ticks) */ +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec; +#else /* HAVE_GETTIMEOFDAY */ + return time(NULL); +#endif /* HAVE_GETTIMEOFDAY */ +}