From: Rosen Penev Date: Sat, 24 Aug 2019 22:01:16 +0000 (-0700) Subject: os_sleep: Use nanosleep for POSIX versions 2008 and higher X-Git-Tag: hostap_2_10~2380 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=39042d7f7c4997af55474ebe4513c81f00732837;p=thirdparty%2Fhostap.git os_sleep: Use nanosleep for POSIX versions 2008 and higher 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 --- diff --git a/src/utils/os_internal.c b/src/utils/os_internal.c index 474c8a372..feade6ee6 100644 --- a/src/utils/os_internal.c +++ b/src/utils/os_internal.c @@ -25,10 +25,16 @@ void os_sleep(os_time_t sec, os_time_t usec) { +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) + const struct timespec req = { sec, usec * 1000 }; + + nanosleep(&req, NULL); +#else if (sec) sleep(sec); if (usec) usleep(usec); +#endif } diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c index 800c50772..dd504f3ab 100644 --- a/src/utils/os_unix.c +++ b/src/utils/os_unix.c @@ -49,10 +49,16 @@ struct os_alloc_trace { void os_sleep(os_time_t sec, os_time_t usec) { +#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L) + const struct timespec req = { sec, usec * 1000 }; + + nanosleep(&req, NULL); +#else if (sec) sleep(sec); if (usec) usleep(usec); +#endif }