From: Jarkko Hietaniemi Date: Wed, 8 May 2002 23:20:29 +0000 (+0000) Subject: Rework #16503 a bit to keep all the HiRes implementation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd44fdfdcab7b04058a73915d0e1699f8f201a6f;p=p5sagit%2Fp5-mst-13.2.git Rework #16503 a bit to keep all the HiRes implementation in one place, assuming we want to re-CPAN Time::HiRes at some point. p4raw-id: //depot/perl@16506 --- diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index 0c9e445..c38dc07 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -58,6 +58,43 @@ not_there: return 0; } +#if !defined(HAS_GETTIMEOFDAY) && defined(WIN32) +#define HAS_GETTIMEOFDAY + +typedef union { + unsigned __int64 ft_i64; + FILETIME ft_val; +} FT_t; + +#ifdef __GNUC__ +#define Const64(x) x##LL +#else +#define Const64(x) x##i64 +#endif +/* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */ +#define EPOCH_BIAS Const64(116444736000000000) + +/* NOTE: This does not compute the timezone info (doing so can be expensive, + * and appears to be unsupported even by glibc) */ +DllExport int +gettimeofday(struct timeval *tp, void *not_used) +{ + FT_t ft; + + /* this returns time in 100-nanosecond units (i.e. tens of usecs) */ + GetSystemTimeAsFileTime(&ft.ft_val); + + /* seconds since epoch */ + tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000)); + + /* microseconds remaining */ + tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000)); + + return 0; +} + +#endif /* WIN32 */ + #if !defined(HAS_GETTIMEOFDAY) && defined(VMS) #define HAS_GETTIMEOFDAY diff --git a/win32/win32.c b/win32/win32.c index 06068bf..59e7ee8 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1651,36 +1651,12 @@ win32_utime(const char *filename, struct utimbuf *times) return rc; } -typedef union { - unsigned __int64 ft_i64; - FILETIME ft_val; -} FT_t; - -#ifdef __GNUC__ -#define Const64(x) x##LL -#else -#define Const64(x) x##i64 -#endif -/* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */ -#define EPOCH_BIAS Const64(116444736000000000) - /* NOTE: This does not compute the timezone info (doing so can be expensive, * and appears to be unsupported even by glibc) */ DllExport int win32_gettimeofday(struct timeval *tp, void *not_used) { - FT_t ft; - - /* this returns time in 100-nanosecond units (i.e. tens of usecs) */ - GetSystemTimeAsFileTime(&ft.ft_val); - - /* seconds since epoch */ - tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000)); - - /* microseconds remaining */ - tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000)); - - return 0; + return PerlProc_gettimeofday(tp, not_used); // Implemented in Time::HiRes. } DllExport int