From 95d8811c2cef8bcde78e1f172f6c57c25cd487aa Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Fri, 14 Jan 2011 21:22:46 +0100 Subject: [PATCH] Proper check and dropin replacement for usleep(). --- configure.in | 2 +- src/dropin.c | 5 +++-- src/dropin.h | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index 8e718c83..d20da0cb 100644 --- a/configure.in +++ b/configure.in @@ -136,7 +136,7 @@ dnl Checks for library functions. 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 time 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 time unsetenv usleep vsyslog writev], [], [], [#include "have.h"] ) AC_FUNC_MALLOC diff --git a/src/dropin.c b/src/dropin.c index 52fb5b86..1bad05cd 100644 --- a/src/dropin.c +++ b/src/dropin.c @@ -164,9 +164,10 @@ int gettimeofday(struct timeval *tv, void *tz) { } #endif -#ifdef HAVE_MINGW +#ifndef HAVE_USLEEP int usleep(long usec) { - Sleep(usec / 1000); + struct timeval tv = {usec / 1000000, (usec / 1000) % 1000}; + select(0, NULL, NULL, NULL, &tv); return 0; } #endif diff --git a/src/dropin.h b/src/dropin.h index e9d13535..a4d92480 100644 --- a/src/dropin.h +++ b/src/dropin.h @@ -41,4 +41,8 @@ extern int vasprintf(char **, const char *, va_list ap); extern int gettimeofday(struct timeval *, void *); #endif +#ifndef HAVE_USLEEP +extern int usleep(long); +#endif + #endif /* __DROPIN_H__ */ -- 2.20.1