diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2002-05-08 22:49:33 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2002-05-08 22:49:33 +0000 |
commit | 57ab3dfef762780a52fccd428b2a630bc33a48f4 (patch) | |
tree | 22d944da0465db82999d4d066201b8145bc1641c /win32/win32.c | |
parent | dd15e2708920dbc7ca0967cd7bb3cf4d1bdabec2 (diff) | |
download | perl-57ab3dfef762780a52fccd428b2a630bc33a48f4.tar.gz |
make the gettimeofday() implementation in Time::HiRes available
from perl
p4raw-id: //depot/perl@16503
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c index ca684c84cd..06068bf043 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1651,6 +1651,38 @@ 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; +} + DllExport int win32_uname(struct utsname *name) { |