Linux: Fix a major regression in threads_posix.c
authorPete Batard <pete@akeo.ie>
Wed, 6 Jun 2012 09:53:43 +0000 (10:53 +0100)
committerPete Batard <pete@akeo.ie>
Wed, 6 Jun 2012 09:53:43 +0000 (10:53 +0100)
* On some Linux platforms, libusbx compilation breaks with:
  error: implicit declaration of function ‘pthread_mutexattr_settype’
* This regression, introduced in 463dda06db5da5de0eab32820c7af60605625afe,
  is due to pthread.h needing __USE_UNIX98, which is tied to _XOPEN_SOURCE
  or _GNU_SOURCE being correctly defined, and which the inclusion of
  <unistd.h> before the _XOPEN_SOURCE override modified
* As _GNU_LINUX ensures the definition of __USE_UNIX98 and we require it
  for syscalls, we now only define _GNU_SOURCE for Linux.

libusb/os/threads_posix.c
libusb/version_nano.h

index dc182b7..9769f58 100644 (file)
  */
 
 #if defined(__linux__) || defined(__OpenBSD__)
+# if defined(__linux__)
+#  define _GNU_SOURCE
+# else
+#  define _BSD_SOURCE
+# endif
 # include <unistd.h>
 # include <sys/syscall.h>
 #elif defined(__APPLE__)
 # include <windows.h>
 #endif
 
-#ifdef _XOPEN_SOURCE
-# if _XOPEN_SOURCE < 500
-#  undef _XOPEN_SOURCE
-#  define _XOPEN_SOURCE 500
-# endif
-#else
-#define _XOPEN_SOURCE 500
-#endif /* _XOPEN_SOURCE */
-
 #include "threads_posix.h"
 
 int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
@@ -50,6 +46,7 @@ int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr)
                        return err;
        }
 
+       /* mutexattr_settype requires _GNU_SOURCE or _XOPEN_SOURCE >= 500 on Linux */
        err = pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE);
        if (err != 0)
                goto finish;
index f56fbab..8d7dc39 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 10520
+#define LIBUSB_NANO 10521