]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
libzrtp: update zrtp_sleep for modern libc
authorPeter Wu <peter@lekensteyn.nl>
Wed, 6 Aug 2014 08:19:03 +0000 (10:19 +0200)
committerTravis Cross <tc@traviscross.com>
Wed, 13 Aug 2014 19:28:55 +0000 (19:28 +0000)
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);
      ^

libs/libzrtp/configure.ac
libs/libzrtp/src/zrtp_iface_scheduler.c

index d1c40b7e3d332a9a6a4bab0c2ac16d35b0e0d10e..251c51acc18ce1191c40388fe0d1678824167f27 100644 (file)
@@ -68,7 +68,7 @@ AC_C_CONST
 # Checks for library functions.
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([memset memcpy malloc free]) 
-AC_CHECK_FUNCS([usleep])
+AC_CHECK_FUNCS([usleep nanosleep])
 AC_CHECK_FUNCS([fopen fread])
 AC_CHECK_FUNCS([pthread_mutex_lock pthread_mutex_unlock pthread_mutex_init pthread_mutex_destroy])
 AC_CHECK_FUNCS([pthread_attr_init pthread_attr_setdetachstate pthread_create])
index 715c584b532864e50a6341fd2465a5ef6f08d3f7..16386cafdbe8bcad74937b5dd271c6927e8c570d 100644 (file)
@@ -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;
 }