MacOS Classic timeofday(), from Chris Nandor.
Jarkko Hietaniemi [Mon, 22 Oct 2001 21:23:15 +0000 (21:23 +0000)]
p4raw-id: //depot/perl@12594

ext/Time/HiRes/HiRes.xs

index 3bb1aa4..e0ac4fb 100644 (file)
@@ -442,7 +442,41 @@ alarm(fseconds,finterval=0)
 #endif
 
 #ifdef HAS_GETTIMEOFDAY
+#    ifdef MACOS_TRADITIONAL   /* fix epoch TZ and use unsigned time_t */
+void
+gettimeofday()
+        PREINIT:
+        struct timeval Tp;
+        struct timezone Tz;
+        PPCODE:
+        int status;
+        status = gettimeofday (&Tp, &Tz);
+        Tp.tv_sec += Tz.tz_minuteswest * 60;   /* adjust for TZ */
+
+        if (GIMME == G_ARRAY) {
+             EXTEND(sp, 2);
+             /* Mac OS (Classic) has unsigned time_t */
+             PUSHs(sv_2mortal(newSVuv(Tp.tv_sec)));
+             PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
+        } else {
+             EXTEND(sp, 1);
+             PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
+        }
+
+NV
+time()
+        PREINIT:
+        struct timeval Tp;
+        struct timezone Tz;
+        CODE:
+        int status;
+        status = gettimeofday (&Tp, &Tz);
+        Tp.tv_sec += Tz.tz_minuteswest * 60;   /* adjust for TZ */
+        RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.0);
+       OUTPUT:
+       RETVAL
 
+#    else      /* MACOS_TRADITIONAL */
 void
 gettimeofday()
         PREINIT:
@@ -470,6 +504,7 @@ time()
        OUTPUT:
        RETVAL
 
+#    endif     /* MACOS_TRADITIONAL */
 #endif
 
 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)