[PATCH v2 2/2] libbb: provide usleep() fallback implementation
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Tue Apr 8 13:11:34 UTC 2014
POSIX.1-2008 removed the usleep function, provide a fallback
implementaion using the recommended nanosleep().
function old new delta
usleep - 49 +49
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/0 up/down: 49/0) Total: 49 bytes
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
include/platform.h | 9 +++++++++
libbb/platform.c | 10 ++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/platform.h b/include/platform.h
index bd11ad6..4396432 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -384,6 +384,11 @@ typedef unsigned smalluint;
#if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
# undef HAVE_STRVERSCMP
#endif
+#if defined(__UCLIBC__) && UCLIBC_VERSION >= KERNEL_VERSION(0, 9, 30)
+# ifndef __UCLIBC_SUSV3_LEGACY__
+# undef HAVE_USLEEP
+# endif
+#endif
#if defined(__WATCOMC__)
# undef HAVE_DPRINTF
@@ -519,6 +524,10 @@ extern char *strsep(char **stringp, const char *delim) FAST_FUNC;
# define strsignal(sig) get_signame(sig)
#endif
+#ifndef HAVE_USLEEP
+extern int usleep(unsigned int) FAST_FUNC;
+#endif
+
#ifndef HAVE_VASPRINTF
extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
#endif
diff --git a/libbb/platform.c b/libbb/platform.c
index 1973451..4253209 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -17,6 +17,16 @@ char* FAST_FUNC strchrnul(const char *s, int c)
}
#endif
+#ifndef HAVE_USLEEP
+int FAST_FUNC usleep(unsigned int usec)
+{
+ struct timespec ts;
+ ts.tv_sec = usec / 1000000;
+ ts.tv_nsec = (usec % 1000000) * 1000;
+ return nanosleep(&ts, NULL); /* could loop as well */
+}
+#endif
+
#ifndef HAVE_VASPRINTF
int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
{
--
1.9.1
More information about the busybox
mailing list