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 <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-08-24 15:01:16 -07:00 committed by Jouni Malinen
parent a69742c2f8
commit 39042d7f7c
2 changed files with 12 additions and 0 deletions

View file

@ -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
}

View file

@ -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
}