Paul Fertser
2010-Dec-20 10:50 UTC
[PATCH 1/2] Add usleep() implementation for systems that lack it
This is needed e.g. on Debian which ships a really ancient version of mingw runtime. --- common/wincompat.c | 17 +++++++++++++++++ configure.in | 1 + include/common.h | 4 ++++ 3 files changed, 22 insertions(+), 0 deletions(-) diff --git a/common/wincompat.c b/common/wincompat.c index 3873d2c..a9fbabc 100644 --- a/common/wincompat.c +++ b/common/wincompat.c @@ -26,6 +26,23 @@ extern int errno; const char * EventLogName = NULL; +#ifndef HAVE_USLEEP +/* Verbatim from + http://cygwin.com/cgi-bin/cvsweb.cgi/~checkout~/src/winsup/mingw/mingwex/usleep.c?rev=1.2&cvsroot=src */ +int __cdecl usleep(unsigned int useconds) +{ + if(useconds == 0) + return 0; + + if(useconds >= 1000000) + return EINVAL; + + Sleep((useconds + 999) / 1000); + + return 0; +} +#endif /* !HAVE_USLEEP */ + int sktconnect(int fh, struct sockaddr * name, int len) { int ret = connect(fh,name,len); diff --git a/configure.in b/configure.in index 528ffcd..6bc263e 100644 --- a/configure.in +++ b/configure.in @@ -89,6 +89,7 @@ AC_CHECK_FUNCS(flock lockf fcvt fcvtl) AC_CHECK_FUNCS(cfsetispeed tcsendbreak) AC_CHECK_FUNCS(seteuid setsid getpassphrase) AC_CHECK_FUNCS(on_exit strptime setlogmask) +AC_CHECK_FUNCS(usleep) AC_CHECK_DECLS(LOG_UPTO, [], [], [#include <syslog.h>]) dnl the following may add stuff to LIBOBJS (is this still needed?) diff --git a/include/common.h b/include/common.h index dbeec9a..2fde7a5 100644 --- a/include/common.h +++ b/include/common.h @@ -182,4 +182,8 @@ extern int optind; #endif /* WIN32*/ +#ifndef HAVE_USLEEP +int __cdecl usleep(unsigned int useconds); +#endif /* HAVE_USLEEP */ + #endif /* NUT_COMMON_H */ -- 1.5.6.5 --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0002-Automatically-find-the-appropriate-windows-specific.patch"