aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2014-04-13 16:37:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-04-13 16:37:57 +0200
commitad16741ccd8a8587644d88fb8fdfc41ada1928a6 (patch)
treeaa6461272aa3b71bb2f2f8da4b91a31d8b35eb59
parent69b114fb8a2566e14ce125f7736add9dacf6e18d (diff)
downloadbusybox-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>
-rw-r--r--include/platform.h16
-rw-r--r--libbb/platform.c18
2 files changed, 32 insertions, 2 deletions
diff --git a/include/platform.h b/include/platform.h
index bd11ad69a..92f775551 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -373,6 +373,7 @@ typedef unsigned smalluint;
373#define HAVE_STRSIGNAL 1 373#define HAVE_STRSIGNAL 1
374#define HAVE_STRVERSCMP 1 374#define HAVE_STRVERSCMP 1
375#define HAVE_VASPRINTF 1 375#define HAVE_VASPRINTF 1
376#define HAVE_USLEEP 1
376#define HAVE_UNLOCKED_STDIO 1 377#define HAVE_UNLOCKED_STDIO 1
377#define HAVE_UNLOCKED_LINE_OPS 1 378#define HAVE_UNLOCKED_LINE_OPS 1
378#define HAVE_GETLINE 1 379#define HAVE_GETLINE 1
@@ -381,8 +382,15 @@ typedef unsigned smalluint;
381#define HAVE_NET_ETHERNET_H 1 382#define HAVE_NET_ETHERNET_H 1
382#define HAVE_SYS_STATFS_H 1 383#define HAVE_SYS_STATFS_H 1
383 384
384#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32) 385#if defined(__UCLIBC__)
385# undef HAVE_STRVERSCMP 386# if UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
387# undef HAVE_STRVERSCMP
388# endif
389# if UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
390# ifndef __UCLIBC_SUSV3_LEGACY__
391# undef HAVE_USLEEP
392# endif
393# endif
386#endif 394#endif
387 395
388#if defined(__WATCOMC__) 396#if defined(__WATCOMC__)
@@ -519,6 +527,10 @@ extern char *strsep(char **stringp, const char *delim) FAST_FUNC;
519# define strsignal(sig) get_signame(sig) 527# define strsignal(sig) get_signame(sig)
520#endif 528#endif
521 529
530#ifndef HAVE_USLEEP
531extern int usleep(unsigned) FAST_FUNC;
532#endif
533
522#ifndef HAVE_VASPRINTF 534#ifndef HAVE_VASPRINTF
523extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC; 535extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
524#endif 536#endif
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
21int 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
21int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p) 39int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
22{ 40{