diff options
| author | cremno <[email protected]> | 2014-03-04 20:36:00 +0100 |
|---|---|---|
| committer | cremno <[email protected]> | 2014-03-05 17:13:13 +0100 |
| commit | 890ef11fdecddee775e98f3243ec67a669bc1fe1 (patch) | |
| tree | bfe5f910ac3a3507879cccb784f2b3c8fd037ecc | |
| parent | 2f20463b7746aefd7d5334166590bb633753ccdd (diff) | |
| download | mruby-890ef11fdecddee775e98f3243ec67a669bc1fe1.tar.gz mruby-890ef11fdecddee775e98f3243ec67a669bc1fe1.zip | |
mruby-time: add gettimeofday(2) for Windows
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 2e72c5c53..1e9162821 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -42,7 +42,37 @@ /** end of Time class configuration */ #ifndef NO_GETTIMEOFDAY -#include <sys/time.h> +# ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN /* don't include winsock.h */ +# include <windows.h> +# define gettimeofday my_gettimeofday +typedef long suseconds_t; +struct timeval { + time_t tv_sec; + suseconds_t tv_usec; +}; +static int +gettimeofday(struct timeval *tv, void *tz) +{ + if (tz) { + mrb_assert(0); /* timezone is not supported */ + } + if (tv) { + union { + FILETIME ft; + unsigned __int64 u64; + } t; + GetSystemTimeAsFileTime(&t.ft); /* 100 ns intervals since Windows epoch */ + t.u64 -= 116444736000000000ui64; /* Unix epoch bias */ + t.u64 /= 10; /* to microseconds */ + tv->tv_sec = (time_t)(t.u64 / 1000 * 1000); + tv->tv_usec = t.u64 % 1000 * 1000; + } + return 0; +} +# else +# include <sys/time.h> +# endif #endif #ifdef NO_GMTIME_R #define gmtime_r(t,r) gmtime(t) |
