Rework #16506 some more.
[p5sagit/p5-mst-13.2.git] / ext / Time / HiRes / HiRes.xs
index e1e13e1..9d3586d 100644 (file)
@@ -9,6 +9,11 @@ extern "C" {
 #else
 #include <sys/time.h>
 #endif
+#ifdef HAS_SELECT
+# ifdef I_SYS_SELECT
+#  include <sys/select.h>
+# endif
+#endif
 #ifdef __cplusplus
 }
 #endif
@@ -560,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);
 }
@@ -613,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);