X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FTime%2FHiRes%2FHiRes.xs;h=9d3586dee8325d74b05d4474371f564e0f9e58b7;hb=6e3b076d535420d10e4d928a62445e7e7b46eef7;hp=952544ead2e9dcc80dc7bfc8275999d1f7694765;hpb=ca40fe497003abfacd4354515838e1c3b79d0ceb;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index 952544e..9d3586d 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -9,6 +9,11 @@ extern "C" { #else #include #endif +#ifdef HAS_SELECT +# ifdef I_SYS_SELECT +# include +# endif +#endif #ifdef __cplusplus } #endif @@ -69,7 +74,12 @@ typedef union { } FT_t; /* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */ -#define EPOCH_BIAS 116444736000000000i64 +#ifdef __GNUC__ +#define Const64(x) x##LL +#else +#define Const64(x) x##i64 +#endif +#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) */ @@ -82,10 +92,10 @@ gettimeofday (struct timeval *tp, void *not_used) GetSystemTimeAsFileTime(&ft.ft_val); /* seconds since epoch */ - tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / 10000000i64); + tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / Const64(10000000)); /* microseconds remaining */ - tp->tv_usec = (long)((ft.ft_i64 / 10i64) % 1000000i64); + tp->tv_usec = (long)((ft.ft_i64 / Const64(10)) % Const64(1000000)); return 0; } @@ -555,7 +565,7 @@ BOOT: #ifdef HAS_GETTIMEOFDAY { UV auv[2]; - hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime()), 0); + hv_store(PL_modglobal, "Time::NVtime", 12, newSViv(PTR2IV(myNVtime)), 0); if (myU2time(auv) == 0) hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) auv[0]), 0); } @@ -608,8 +618,9 @@ sleep(...) if (items > 0) { NV seconds = SvNV(ST(0)); if (seconds >= 0.0) { - UV useconds = 1E6 * (seconds - (UV)seconds); - sleep((UV)seconds); + UV useconds = (UV)(1E6 * (seconds - (UV)seconds)); + if (seconds >= 1.0) + sleep((UV)seconds); usleep(useconds); } else croak("Time::HiRes::sleep(%"NVgf"): negative time not invented yet", seconds);