Proper check and dropin replacement for usleep().
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 12 Jan 2011 19:57:14 +0000 (20:57 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 12 Jan 2011 19:57:14 +0000 (20:57 +0100)
configure.in
lib/dropin.c
lib/dropin.h

index 8e1ae87..078a7f1 100644 (file)
@@ -128,7 +128,7 @@ dnl Checks for library functions.
 AC_FUNC_MEMCMP
 AC_FUNC_ALLOCA
 AC_TYPE_SIGNAL
 AC_FUNC_MEMCMP
 AC_FUNC_ALLOCA
 AC_TYPE_SIGNAL
-AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall putenv random select strdup strerror strsignal strtol system unsetenv vsyslog writev],
+AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall putenv random select strdup strerror strsignal strtol system unsetenv usleep vsyslog writev],
   [], [], [#include "have.h"]
 )
 AC_FUNC_MALLOC
   [], [], [#include "have.h"]
 )
 AC_FUNC_MALLOC
index 52fb5b8..1bad05c 100644 (file)
@@ -164,9 +164,10 @@ int gettimeofday(struct timeval *tv, void *tz) {
 }
 #endif
 
 }
 #endif
 
-#ifdef HAVE_MINGW
+#ifndef HAVE_USLEEP
 int usleep(long usec) {
 int usleep(long usec) {
-       Sleep(usec / 1000);
+       struct timeval tv = {usec / 1000000, (usec / 1000) % 1000};
+       select(0, NULL, NULL, NULL, &tv);
        return 0;
 }
 #endif
        return 0;
 }
 #endif
index d5cf6d2..a4d9248 100644 (file)
@@ -41,7 +41,7 @@ extern int vasprintf(char **, const char *, va_list ap);
 extern int gettimeofday(struct timeval *, void *);
 #endif
 
 extern int gettimeofday(struct timeval *, void *);
 #endif
 
-#ifdef HAVE_MINGW
+#ifndef HAVE_USLEEP
 extern int usleep(long);
 #endif
 
 extern int usleep(long);
 #endif