[flashrom] [PATCH] Use nanosleep() instead of usleep() where available.

Stefan Tauner stefan.tauner at alumni.tuwien.ac.at
Sun Nov 1 05:16:27 CET 2015


usleep() has been obsolete for quite a while.
The only target where it is currently used without alternative is DOS.

Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
---

While setting up uClibc on the buildbot in a rather limited configuration
I noticed that the only thing that made it fail was the use of usleep().
usleep() has been made obsolete with POSIX.1-2001 and was removed in
POSIX.1-2008 hence it would be great to get rid of it completely.
However, DJGPP for DOS does not provide an alternative so we are stuck
there. Still, we can migrate everything else (but Windows) to nanosleep
with this patch. Verified against the buildbot.

 udelay.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/udelay.c b/udelay.c
index c03bcc4..60a8604 100644
--- a/udelay.c
+++ b/udelay.c
@@ -22,6 +22,7 @@
 #ifndef __LIBPAYLOAD__
 
 #include <unistd.h>
+#include <time.h>
 #include <sys/time.h>
 #include <stdlib.h>
 #include <limits.h>
@@ -174,9 +175,11 @@ void internal_sleep(unsigned int usecs)
 {
 #if IS_WINDOWS
 	Sleep((usecs + 999) / 1000);
-#else
+#elif defined(__DJGPP__)
 	sleep(usecs / 1000000);
 	usleep(usecs % 1000000);
+#else
+	nanosleep(&(struct timespec){usecs / 1000000, (usecs * 1000) % 1000000000}, NULL);
 #endif
 }
 
-- 
Kind regards, Stefan Tauner





More information about the flashrom mailing list