diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-05-14 01:29:05 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-05-14 01:29:29 -0700 |
commit | 4132bd74e9816ca913f862835cc062e092ab8b79 (patch) | |
tree | 7861e23ef6007320ca0417a147656cf9774473b7 /lib/gettimeofday.c | |
parent | 9a5e864de731e113badbe300b1e4174f103547fa (diff) | |
download | emacs-4132bd74e9816ca913f862835cc062e092ab8b79.tar.gz |
Merge from gnulib
This incorporates:
2017-05-13 largefile: Simplify
2017-05-13 largefile: Improve and document
2017-05-13 truncate: New module
2017-05-13 windows-stat-timespec: New module
2017-05-13 windows-stat-override: New module
2017-05-11 getopt-posix: port to mingw
2017-05-11 gettimeofday: Increase precision on mingw
2017-05-10 time: Fix missing initialization of HAVE_TIMEZONE_T
2017-05-10 Implement a way to opt out from MSVC support
2017-05-09 tzset: Expand comment about TZ problem on native Windows
* build-aux/config.guess, lib/dup2.c, lib/fcntl.c, lib/fsync.c:
* lib/getdtablesize.c, lib/getopt.c, lib/gettimeofday.c:
* lib/mktime.c, lib/stat-time.h, lib/sys_stat.in.h, lib/unistd.in.h:
* lib/utimens.c, m4/gettimeofday.m4, m4/largefile.m4:
* m4/sys_stat_h.m4, m4/sys_time_h.m4, m4/time_h.m4, m4/time_rz.m4:
* m4/unistd_h.m4: Copy from gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib/gettimeofday.c')
-rw-r--r-- | lib/gettimeofday.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index 1039f77d182..8ae7622af31 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c @@ -64,42 +64,20 @@ int gettimeofday (struct timeval *restrict tv, void *restrict tz) { #undef gettimeofday -#if HAVE_GETTIMEOFDAY -# if GETTIMEOFDAY_CLOBBERS_LOCALTIME - /* Save and restore the contents of the buffer used for localtime's - result around the call to gettimeofday. */ - struct tm save = *localtime_buffer_addr; -# endif - -# if defined timeval /* 'struct timeval' overridden by gnulib? */ -# undef timeval - struct timeval otv; - int result = gettimeofday (&otv, (struct timezone *) tz); - if (result == 0) - { - tv->tv_sec = otv.tv_sec; - tv->tv_usec = otv.tv_usec; - } -# else - int result = gettimeofday (tv, (struct timezone *) tz); -# endif - -# if GETTIMEOFDAY_CLOBBERS_LOCALTIME - *localtime_buffer_addr = save; -# endif - - return result; - -#else - -# ifdef WINDOWS_NATIVE +#ifdef WINDOWS_NATIVE /* On native Windows, there are two ways to get the current time: GetSystemTimeAsFileTime <https://msdn.microsoft.com/en-us/library/ms724397.aspx> or GetSystemTimePreciseAsFileTime - <https://msdn.microsoft.com/en-us/library/hh706895.aspx>. */ + <https://msdn.microsoft.com/en-us/library/hh706895.aspx>. + GetSystemTimeAsFileTime produces values that jump by increments of + 15.627 milliseconds (!) on average. + Whereas GetSystemTimePreciseAsFileTime values usually jump by 1 or 2 + microseconds. + More discussion on this topic: + <http://www.windowstimestamp.com/description>. */ FILETIME current_time; if (!initialized) @@ -122,6 +100,36 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) tv->tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000; tv->tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000; + return 0; + +#else + +# if HAVE_GETTIMEOFDAY +# if GETTIMEOFDAY_CLOBBERS_LOCALTIME + /* Save and restore the contents of the buffer used for localtime's + result around the call to gettimeofday. */ + struct tm save = *localtime_buffer_addr; +# endif + +# if defined timeval /* 'struct timeval' overridden by gnulib? */ +# undef timeval + struct timeval otv; + int result = gettimeofday (&otv, (struct timezone *) tz); + if (result == 0) + { + tv->tv_sec = otv.tv_sec; + tv->tv_usec = otv.tv_usec; + } +# else + int result = gettimeofday (tv, (struct timezone *) tz); +# endif + +# if GETTIMEOFDAY_CLOBBERS_LOCALTIME + *localtime_buffer_addr = save; +# endif + + return result; + # else # if !defined OK_TO_USE_1S_CLOCK @@ -131,9 +139,8 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) tv->tv_sec = time (NULL); tv->tv_usec = 0; -# endif - return 0; +# endif #endif } |