[PATCH] os_sleep: Use nanosleep for POSIX versions 2008 and higher

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



uClibc-ng optionally disabled deprecated POSIX functions like usleep,
causing compilation failures. This switches to nanosleep while retaining
support for older libcs that do not support nanosleep.

Signed-off-by: Rosen Penev <rosenp@xxxxxxxxx>
---
 src/utils/os_internal.c | 7 +++++++
 src/utils/os_unix.c     | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/src/utils/os_internal.c b/src/utils/os_internal.c
index 474c8a372..9134331bf 100644
--- a/src/utils/os_internal.c
+++ b/src/utils/os_internal.c
@@ -28,7 +28,14 @@ void os_sleep(os_time_t sec, os_time_t usec)
 	if (sec)
 		sleep(sec);
 	if (usec)
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
+	{
+		const struct timespec req = {0, usec * 1000};
+		nanosleep (&req, NULL);
+	}
+#else
 		usleep(usec);
+#endif
 }
 
 
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index 800c50772..88af4c4c0 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -52,7 +52,14 @@ void os_sleep(os_time_t sec, os_time_t usec)
 	if (sec)
 		sleep(sec);
 	if (usec)
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
+	{
+		const struct timespec req = {0, usec * 1000};
+		nanosleep(&req, NULL);
+	}
+#else
 		usleep(usec);
+#endif
 }
 
 
-- 
2.17.1


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux