summaryrefslogtreecommitdiff
path: root/lib/usleep.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usleep.c')
-rw-r--r--lib/usleep.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/usleep.c b/lib/usleep.c
index f7e248027f..480605fa95 100644
--- a/lib/usleep.c
+++ b/lib/usleep.c
@@ -28,6 +28,11 @@
#include <errno.h>
+#if defined _WIN32 && ! defined __CYGWIN__
+# define WIN32_LEAN_AND_MEAN /* avoid including junk */
+# include <windows.h>
+#endif
+
#ifndef HAVE_USLEEP
# define HAVE_USLEEP 0
#endif
@@ -39,7 +44,20 @@
int
usleep (useconds_t micro)
+#undef usleep
{
+#if defined _WIN32 && ! defined __CYGWIN__
+ unsigned int milliseconds = micro / 1000;
+ if (sizeof milliseconds < sizeof micro && micro / 1000 != milliseconds)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ if (micro % 1000)
+ milliseconds++;
+ Sleep (milliseconds);
+ return 0;
+#else
unsigned int seconds = micro / 1000000;
if (sizeof seconds < sizeof micro && micro / 1000000 != seconds)
{
@@ -50,9 +68,9 @@ usleep (useconds_t micro)
seconds++;
while ((seconds = sleep (seconds)) != 0);
-#undef usleep
-#if !HAVE_USLEEP
-# define usleep(x) 0
-#endif
+# if !HAVE_USLEEP
+# define usleep(x) 0
+# endif
return usleep (micro % 1000000);
+#endif
}