From ad16741ccd8a8587644d88fb8fdfc41ada1928a6 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Sun, 13 Apr 2014 16:37:57 +0200 Subject: libbb: provide usleep() fallback implementation POSIX.1-2008 removed the usleep function, provide a fallback implementaion using the recommended nanosleep(). Signed-off-by: Bernhard Reutner-Fischer Signed-off-by: Denys Vlasenko --- libbb/platform.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libbb/platform.c') diff --git a/libbb/platform.c b/libbb/platform.c index 19734517b..8d90ca4e9 100644 --- a/libbb/platform.c +++ b/libbb/platform.c @@ -17,6 +17,24 @@ char* FAST_FUNC strchrnul(const char *s, int c) } #endif +#ifndef HAVE_USLEEP +int FAST_FUNC usleep(unsigned usec) +{ + struct timespec ts; + ts.tv_sec = usec / 1000000u; + ts.tv_nsec = (usec % 1000000u) * 1000u; + /* + * If a signal has non-default handler, nanosleep returns early. + * Our version of usleep doesn't return early + * if interrupted by such signals: + * + */ + while (nanosleep(&ts, &ts) != 0) + continue; + return 0; +} +#endif + #ifndef HAVE_VASPRINTF int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) { -- cgit v1.2.3