[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 2/2] libbb: provide usleep() fallback implementation
From:       Bernhard Reutner-Fischer <rep.dot.nop () gmail ! com>
Date:       2014-04-08 13:04:51
Message-ID: 1396962291-32471-3-git-send-email-rep.dot.nop () gmail ! com
[Download RAW message or body]

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@gmail.com>
---
 include/platform.h |  7 +++++++
 libbb/platform.c   | 10 ++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/platform.h b/include/platform.h
index bd11ad6..f013c6b 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -383,6 +383,9 @@ typedef unsigned smalluint;
 
 #if defined(__UCLIBC__) && UCLIBC_VERSION < KERNEL_VERSION(0, 9, 32)
 # undef HAVE_STRVERSCMP
+# ifndef __UCLIBC_SUSV3_LEGACY__
+#  undef HAVE_USLEEP
+# endif
 #endif
 
 #if defined(__WATCOMC__)
@@ -519,6 +522,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

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic