From 0b0b7c7da3066c32fee59649de6c03b788d35572 Mon Sep 17 00:00:00 2001 From: brarcher Date: Wed, 25 Dec 2013 03:04:09 +0000 Subject: [PATCH] libcompat: add alternative for gettimeofday git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@934 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- configure.ac | 4 ++-- lib/gettimeofday.c | 29 +++++++++++++++++++++++++++++ lib/libcompat.h | 4 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 lib/gettimeofday.c diff --git a/configure.ac b/configure.ac index b2d14c5..c047949 100644 --- a/configure.ac +++ b/configure.ac @@ -248,8 +248,8 @@ AC_FUNC_REALLOC # replaced with Check's replacement of these functions. HW_LIBRT_TIMERS -AC_REPLACE_FUNCS([alarm clock_gettime fileno localtime_r pipe putenv setenv sleep strdup strsignal unsetenv]) -AC_CHECK_DECLS([alarm, clock_gettime, fileno, localtime_r, pipe, putenv, setenv, sleep, strdup, strsignal, unsetenv]) +AC_REPLACE_FUNCS([alarm clock_gettime gettimeofday fileno localtime_r pipe putenv setenv sleep strdup strsignal unsetenv]) +AC_CHECK_DECLS([alarm, clock_gettime, gettimeofday, fileno, localtime_r, pipe, putenv, setenv, sleep, strdup, strsignal, unsetenv]) AC_CHECK_FUNCS([setitimer]) diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c new file mode 100644 index 0000000..8b3be8c --- /dev/null +++ b/lib/gettimeofday.c @@ -0,0 +1,29 @@ +#include "libcompat.h" +#include + +#if defined(_MSC_VER) || defined(__BORLANDC__) +#define EPOCHFILETIME (116444736000000000i64) +#else +#define EPOCHFILETIME (116444736000000000LL) +#endif + +int gettimeofday (struct timeval *tv, void* tz) +{ +#if _MSC_VER + union { + __int64 ns100; /*time since 1 Jan 1601 in 100ns units */ + FILETIME ft; + } now; + + GetSystemTimeAsFileTime (&now.ft); + tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL); + tv->tv_sec = (long) ((now.ns100 - EPOCHFILETIME) / 10000000LL); + return (0); +#else + // Return that there is no implementation of this on the system + errno=ENOSYS; + return -1; +#endif /* _MSC_VER */ +} + + diff --git a/lib/libcompat.h b/lib/libcompat.h index 0a12356..55034dc 100644 --- a/lib/libcompat.h +++ b/lib/libcompat.h @@ -92,6 +92,10 @@ int fileno (FILE *stream); #define getpid _getpid; #endif /* !HAVE_GETPID && HAVE__GETPID */ +#if !HAVE_GETTIMEOFDAY +int gettimeofday (struct timeval *tv, void* tz); +#endif /* !HAVE_LOCALTIME_R */ + #if !HAVE_DECL_LOCALTIME_R #if !defined(localtime_r) struct tm *localtime_r (const time_t *clock, struct tm *result); -- 2.40.0