summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--XSUB.h1
-rw-r--r--ext/Time/HiRes/HiRes.xs63
-rw-r--r--iperlsys.h6
-rw-r--r--makedef.pl1
-rw-r--r--pp.c2
-rw-r--r--win32/config.bc2
-rw-r--r--win32/config.gc2
-rw-r--r--win32/config.vc2
-rw-r--r--win32/config.vc644
-rw-r--r--win32/config_H.bc2
-rw-r--r--win32/config_H.gc2
-rw-r--r--win32/config_H.vc2
-rw-r--r--win32/config_H.vc644
-rw-r--r--win32/perlhost.h9
-rw-r--r--win32/win32.c32
-rw-r--r--win32/win32iop.h3
16 files changed, 72 insertions, 65 deletions
diff --git a/XSUB.h b/XSUB.h
index 2bd681c662..d5c777eb81 100644
--- a/XSUB.h
+++ b/XSUB.h
@@ -421,6 +421,7 @@ C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
# define longjmp PerlProc_longjmp
# define signal PerlProc_signal
# define getpid PerlProc_getpid
+# define gettimeofday PerlProc_gettimeofday
# define htonl PerlSock_htonl
# define htons PerlSock_htons
# define ntohl PerlSock_ntohl
diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs
index 9d3586dee8..0c9e44596f 100644
--- a/ext/Time/HiRes/HiRes.xs
+++ b/ext/Time/HiRes/HiRes.xs
@@ -58,49 +58,6 @@ not_there:
return 0;
}
-#if !defined(HAS_GETTIMEOFDAY) && defined(WIN32)
-#define HAS_GETTIMEOFDAY
-
-/* shows up in winsock.h?
-struct timeval {
- long tv_sec;
- long tv_usec;
-}
-*/
-
-typedef union {
- unsigned __int64 ft_i64;
- FILETIME ft_val;
-} FT_t;
-
-/* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */
-#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) */
-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
-
#if !defined(HAS_GETTIMEOFDAY) && defined(VMS)
#define HAS_GETTIMEOFDAY
@@ -540,7 +497,7 @@ myU2time(UV *ret)
{
struct timeval Tp;
int status;
- status = gettimeofday (&Tp, NULL);
+ status = PerlProc_gettimeofday(&Tp,NULL);
ret[0] = Tp.tv_sec;
ret[1] = Tp.tv_usec;
return status;
@@ -551,7 +508,7 @@ myNVtime()
{
struct timeval Tp;
int status;
- status = gettimeofday (&Tp, NULL);
+ status = PerlProc_gettimeofday(&Tp,NULL);
return status == 0 ? Tp.tv_sec + (Tp.tv_usec / 1000000.) : -1.0;
}
@@ -584,7 +541,7 @@ usleep(useconds)
PREINIT:
struct timeval Ta, Tb;
CODE:
- gettimeofday(&Ta, NULL);
+ PerlProc_gettimeofday(&Ta,NULL);
if (items > 0) {
if (useconds > 1E6) {
IV seconds = (IV) (useconds / 1E6);
@@ -600,7 +557,7 @@ usleep(useconds)
usleep((UV)useconds);
} else
PerlProc_pause();
- gettimeofday(&Tb, NULL);
+ PerlProc_gettimeofday(&Tb,NULL);
#if 0
printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
#endif
@@ -614,7 +571,7 @@ sleep(...)
PREINIT:
struct timeval Ta, Tb;
CODE:
- gettimeofday(&Ta, NULL);
+ PerlProc_gettimeofday(&Ta,NULL);
if (items > 0) {
NV seconds = SvNV(ST(0));
if (seconds >= 0.0) {
@@ -626,7 +583,7 @@ sleep(...)
croak("Time::HiRes::sleep(%"NVgf"): negative time not invented yet", seconds);
} else
PerlProc_pause();
- gettimeofday(&Tb, NULL);
+ PerlProc_gettimeofday(&Tb,NULL);
#if 0
printf("[%ld %ld] [%ld %ld]\n", Tb.tv_sec, Tb.tv_usec, Ta.tv_sec, Ta.tv_usec);
#endif
@@ -675,7 +632,7 @@ gettimeofday()
struct timezone Tz;
PPCODE:
int status;
- status = gettimeofday (&Tp, &Tz);
+ status = PerlProc_gettimeofday(&Tp,&Tz);
Tp.tv_sec += Tz.tz_minuteswest * 60; /* adjust for TZ */
if (GIMME == G_ARRAY) {
@@ -695,7 +652,7 @@ time()
struct timezone Tz;
CODE:
int status;
- status = gettimeofday (&Tp, &Tz);
+ status = PerlProc_gettimeofday(&Tp,&Tz);
Tp.tv_sec += Tz.tz_minuteswest * 60; /* adjust for TZ */
RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.0);
OUTPUT:
@@ -708,7 +665,7 @@ gettimeofday()
struct timeval Tp;
PPCODE:
int status;
- status = gettimeofday (&Tp, NULL);
+ status = PerlProc_gettimeofday(&Tp,NULL);
if (GIMME == G_ARRAY) {
EXTEND(sp, 2);
PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
@@ -724,7 +681,7 @@ time()
struct timeval Tp;
CODE:
int status;
- status = gettimeofday (&Tp, NULL);
+ status = PerlProc_gettimeofday(&Tp,NULL);
RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
OUTPUT:
RETVAL
diff --git a/iperlsys.h b/iperlsys.h
index 76a49cd1af..86823df02b 100644
--- a/iperlsys.h
+++ b/iperlsys.h
@@ -953,6 +953,8 @@ typedef int (*LPProcSpawnvp)(struct IPerlProc*, int, const char*,
typedef int (*LPProcASpawn)(struct IPerlProc*, void*, void**, void**);
#endif
typedef int (*LPProcLastHost)(struct IPerlProc*);
+typedef int (*LPProcGetTimeOfDay)(struct IPerlProc*,
+ struct timeval*, void*);
struct IPerlProc
{
@@ -993,6 +995,7 @@ struct IPerlProc
#endif
LPProcLastHost pLastHost;
LPProcPopenList pPopenList;
+ LPProcGetTimeOfDay pGetTimeOfDay;
};
struct IPerlProcInfo
@@ -1076,6 +1079,8 @@ struct IPerlProcInfo
#endif
#define PerlProc_lasthost() \
(*PL_Proc->pLastHost)(PL_Proc)
+#define PerlProc_gettimeofday(t,z) \
+ (*PL_Proc->pGetTimeOfDay)(PL_Proc,(t),(z))
#else /* PERL_IMPLICIT_SYS */
@@ -1110,6 +1115,7 @@ struct IPerlProcInfo
#define PerlProc_signal(n, h) signal((n), (h))
#define PerlProc_fork() my_fork()
#define PerlProc_getpid() getpid()
+#define PerlProc_gettimeofday(t,z) gettimeofday((t),(z))
#ifdef WIN32
#define PerlProc_DynaLoad(f) \
diff --git a/makedef.pl b/makedef.pl
index cae06952b9..1d3f0adab8 100644
--- a/makedef.pl
+++ b/makedef.pl
@@ -1052,6 +1052,7 @@ if ($PLATFORM =~ /^win(?:32|ce)$/) {
win32_link
win32_unlink
win32_utime
+ win32_gettimeofday
win32_uname
win32_wait
win32_waitpid
diff --git a/pp.c b/pp.c
index a2433d9b17..9af36f06c7 100644
--- a/pp.c
+++ b/pp.c
@@ -2680,7 +2680,7 @@ S_seed(pTHX)
u = (U32)SEED_C1 * when[0] + (U32)SEED_C2 * when[1];
#else
# ifdef HAS_GETTIMEOFDAY
- gettimeofday(&when,(struct timezone *) 0);
+ PerlProc_gettimeofday(&when,NULL);
u = (U32)SEED_C1 * when.tv_sec + (U32)SEED_C2 * when.tv_usec;
# else
(void)time(&when);
diff --git a/win32/config.bc b/win32/config.bc
index 679cfdfcf4..69c351642b 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -229,7 +229,7 @@ d_getservent_r='undef'
d_getservprotos='define'
d_getspnam='undef'
d_getspnam_r='undef'
-d_gettimeod='undef'
+d_gettimeod='define'
d_gmtime_r='undef'
d_gnulibc='undef'
d_grpasswd='undef'
diff --git a/win32/config.gc b/win32/config.gc
index 32bbf1c462..0170104062 100644
--- a/win32/config.gc
+++ b/win32/config.gc
@@ -293,7 +293,7 @@ d_getsbyport='define'
d_getsent='undef'
d_getservprotos='define'
d_getspnam='undef'
-d_gettimeod='undef'
+d_gettimeod='define'
d_gnulibc='undef'
d_grpasswd='undef'
d_hasmntopt='undef'
diff --git a/win32/config.vc b/win32/config.vc
index 2b0aea084e..e11c5b3bee 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -229,7 +229,7 @@ d_getservent_r='undef'
d_getservprotos='define'
d_getspnam='undef'
d_getspnam_r='undef'
-d_gettimeod='undef'
+d_gettimeod='define'
d_gmtime_r='undef'
d_gnulibc='undef'
d_grpasswd='undef'
diff --git a/win32/config.vc64 b/win32/config.vc64
index e834d3427a..1c1652bddc 100644
--- a/win32/config.vc64
+++ b/win32/config.vc64
@@ -157,7 +157,7 @@ d_finite='undef'
d_finitel='undef'
d_flexfnam='define'
d_flock='define'
-d_flockproto='undef'
+d_flockproto='define'
d_fork='undef'
d_fp_class='undef'
d_fpathconf='undef'
@@ -229,7 +229,7 @@ d_getservent_r='undef'
d_getservprotos='define'
d_getspnam='undef'
d_getspnam_r='undef'
-d_gettimeod='undef'
+d_gettimeod='define'
d_gmtime_r='undef'
d_gnulibc='undef'
d_grpasswd='undef'
diff --git a/win32/config_H.bc b/win32/config_H.bc
index a754aa9981..6bb8aad76b 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -169,7 +169,7 @@
* <sys/resource.h> needs to be included (see I_SYS_RESOURCE).
* The type "Timeval" should be used to refer to "struct timeval".
*/
-/*#define HAS_GETTIMEOFDAY /**/
+#define HAS_GETTIMEOFDAY /**/
#ifdef HAS_GETTIMEOFDAY
#define Timeval struct timeval /* Structure used by gettimeofday() */
#endif
diff --git a/win32/config_H.gc b/win32/config_H.gc
index 2a8c97baa5..d4aa8db46c 100644
--- a/win32/config_H.gc
+++ b/win32/config_H.gc
@@ -169,7 +169,7 @@
* <sys/resource.h> needs to be included (see I_SYS_RESOURCE).
* The type "Timeval" should be used to refer to "struct timeval".
*/
-/*#define HAS_GETTIMEOFDAY /**/
+#define HAS_GETTIMEOFDAY /**/
#ifdef HAS_GETTIMEOFDAY
#define Timeval struct timeval /* Structure used by gettimeofday() */
#endif
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 9aa8c21677..94cbd1300a 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -169,7 +169,7 @@
* <sys/resource.h> needs to be included (see I_SYS_RESOURCE).
* The type "Timeval" should be used to refer to "struct timeval".
*/
-/*#define HAS_GETTIMEOFDAY /**/
+#define HAS_GETTIMEOFDAY /**/
#ifdef HAS_GETTIMEOFDAY
#define Timeval struct timeval /* Structure used by gettimeofday() */
#endif
diff --git a/win32/config_H.vc64 b/win32/config_H.vc64
index 2771c63e26..c68cbe32c7 100644
--- a/win32/config_H.vc64
+++ b/win32/config_H.vc64
@@ -169,7 +169,7 @@
* <sys/resource.h> needs to be included (see I_SYS_RESOURCE).
* The type "Timeval" should be used to refer to "struct timeval".
*/
-/*#define HAS_GETTIMEOFDAY /**/
+#define HAS_GETTIMEOFDAY /**/
#ifdef HAS_GETTIMEOFDAY
#define Timeval struct timeval /* Structure used by gettimeofday() */
#endif
@@ -3464,7 +3464,7 @@
* to the program to supply one. A good guess is
* extern int flock(int, int);
*/
-/*#define HAS_FLOCK_PROTO /**/
+#define HAS_FLOCK_PROTO /**/
/* HAS_FPCLASSL:
* This symbol, if defined, indicates that the fpclassl routine is
diff --git a/win32/perlhost.h b/win32/perlhost.h
index dfc1ebf947..c91d9a8b90 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -1681,6 +1681,12 @@ PerlProcSignal(struct IPerlProc* piPerl, int sig, Sighandler_t subcode)
return win32_signal(sig, subcode);
}
+int
+PerlProcGetTimeOfDay(struct IPerlProc* piPerl, struct timeval *t, void *z)
+{
+ return win32_gettimeofday(t, z);
+}
+
#ifdef USE_ITHREADS
static THREAD_RET_TYPE
win32_start_child(LPVOID arg)
@@ -1934,7 +1940,8 @@ struct IPerlProc perlProc =
PerlProcSpawnvp,
PerlProcASpawn,
PerlProcLastHost,
- PerlProcPopenList
+ PerlProcPopenList,
+ PerlProcGetTimeOfDay
};
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)
{
diff --git a/win32/win32iop.h b/win32/win32iop.h
index 1568a12207..52c59b45b5 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -134,6 +134,7 @@ DllExport int win32_ioctl(int i, unsigned int u, char *data);
DllExport int win32_link(const char *oldname, const char *newname);
DllExport int win32_unlink(const char *f);
DllExport int win32_utime(const char *f, struct utimbuf *t);
+DllExport int win32_gettimeofday(struct timeval *tp, void *not_used);
DllExport int win32_uname(struct utsname *n);
DllExport int win32_wait(int *status);
DllExport int win32_waitpid(int pid, int *status, int flags);
@@ -178,6 +179,7 @@ END_EXTERN_C
#undef ioctl
#undef unlink
#undef utime
+#undef gettimeofday
#undef uname
#undef wait
@@ -292,6 +294,7 @@ END_EXTERN_C
#define link win32_link
#define unlink win32_unlink
#define utime win32_utime
+#define gettimeofday win32_gettimeofday
#define uname win32_uname
#define wait win32_wait
#define waitpid win32_waitpid