mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-15 05:48:33 +00:00
libzrtp: update zrtp_sleep for modern libc
usleep is deprecated and disabled in glibc 2.12 unless requested. Use
nanosleep instead if available.
This fixes the following compiler warning:
./src/zrtp_iface_scheduler.c: In function 'zrtp_sleep':
./src/zrtp_iface_scheduler.c:96:2: warning: implicit declaration of
function 'usleep' [-Wimplicit-function-declaration]
usleep(msec*1000);
^
This commit is contained in:
1 parent
98502947c8
commit
21c145b108
2 files changed
+14
-2
No files matched your search
@@ -7,6 +7,7 @@
|
||||
* Viktor Krykun <v.krikun at zfoneproject.com>
|
||||
*/
|
||||
|
||||
#define _POSIX_C_SOURCE 199309L /* for struct timespec */
|
||||
#include "zrtp.h"
|
||||
|
||||
#if (defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER ==1))
|
||||
@@ -80,11 +81,15 @@ int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg)
|
||||
}
|
||||
|
||||
#elif (ZRTP_PLATFORM == ZP_LINUX) || (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_BSD) || (ZRTP_PLATFORM == ZP_ANDROID)
|
||||
#if ZRTP_HAVE_UNISTD_H == 1
|
||||
/* POSIX.1-2008 removes usleep, so use nanosleep instead when available */
|
||||
#if ZRTP_HAVE_NANOSLEEP
|
||||
#include <time.h> /* for nanosleep */
|
||||
#elif ZRTP_HAVE_UNISTD_H == 1
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Used environment dosn't have <unistd.h> - zrtp_scheduler can't be build."
|
||||
#endif
|
||||
|
||||
#if ZRTP_HAVE_PTHREAD_H == 1
|
||||
#include <pthread.h>
|
||||
#else
|
||||
@@ -93,7 +98,14 @@ int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg)
|
||||
|
||||
int zrtp_sleep(unsigned int msec)
|
||||
{
|
||||
#if ZRTP_HAVE_NANOSLEEP
|
||||
struct timespec delay;
|
||||
delay.tv_sec = msec / 1000;
|
||||
delay.tv_nsec = (msec % 1000) * 1000000;
|
||||
while (nanosleep(&delay, &delay)) ;
|
||||
#else
|
||||
usleep(msec*1000);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user