diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2014-04-13 16:37:57 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-04-13 16:37:57 +0200 |
| commit | ad16741ccd8a8587644d88fb8fdfc41ada1928a6 (patch) | |
| tree | aa6461272aa3b71bb2f2f8da4b91a31d8b35eb59 /libbb | |
| parent | 69b114fb8a2566e14ce125f7736add9dacf6e18d (diff) | |
| download | busybox-w32-ad16741ccd8a8587644d88fb8fdfc41ada1928a6.tar.gz busybox-w32-ad16741ccd8a8587644d88fb8fdfc41ada1928a6.tar.bz2 busybox-w32-ad16741ccd8a8587644d88fb8fdfc41ada1928a6.zip | |
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 <rep.dot.nop@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/platform.c | 18 |
1 files changed, 18 insertions, 0 deletions
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) | |||
| 17 | } | 17 | } |
| 18 | #endif | 18 | #endif |
| 19 | 19 | ||
| 20 | #ifndef HAVE_USLEEP | ||
| 21 | int FAST_FUNC usleep(unsigned usec) | ||
| 22 | { | ||
| 23 | struct timespec ts; | ||
| 24 | ts.tv_sec = usec / 1000000u; | ||
| 25 | ts.tv_nsec = (usec % 1000000u) * 1000u; | ||
| 26 | /* | ||
| 27 | * If a signal has non-default handler, nanosleep returns early. | ||
| 28 | * Our version of usleep doesn't return early | ||
| 29 | * if interrupted by such signals: | ||
| 30 | * | ||
| 31 | */ | ||
| 32 | while (nanosleep(&ts, &ts) != 0) | ||
| 33 | continue; | ||
| 34 | return 0; | ||
| 35 | } | ||
| 36 | #endif | ||
| 37 | |||
| 20 | #ifndef HAVE_VASPRINTF | 38 | #ifndef HAVE_VASPRINTF |
| 21 | int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) | 39 | int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) |
| 22 | { | 40 | { |
