configure.ac: Check for poll.h, and for nfds_t on Darwin
authorPeter Stuge <peter@stuge.se>
Sat, 30 Oct 2010 20:07:37 +0000 (22:07 +0200)
committerPeter Stuge <peter@stuge.se>
Mon, 13 Jun 2011 20:01:42 +0000 (22:01 +0200)
On Linux, assume nfds_t is always available.

On Darwin, fall back to unsigned int when poll() exists but there
is no nfds_t, such as on Mac OS X before 10.4.

On Windows (both MinGW and Cygwin), always use unsigned int instead
of nfds_t, and don't check for poll.h because we use our own poll()
implementation.

configure.ac
libusb/io.c
libusb/libusbi.h
libusb/os/darwin_usb.c
libusb/os/linux_usbfs.c
libusb/os/poll_posix.h
libusb/os/poll_windows.h
libusb/os/windows_usb.c

index 3dcb02d..c6515ad 100644 (file)
@@ -49,6 +49,8 @@ case $host in
        THREAD_CFLAGS="-pthread"
        PC_LIBS_PRIVATE="${PC_LIBS_PRIVATE} -pthread"
        AM_LDFLAGS=""
+       AC_CHECK_HEADERS([poll.h])
+       AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
        ;;
 *-darwin*)
        AC_DEFINE(OS_DARWIN, [], [Darwin backend])
@@ -60,6 +62,11 @@ case $host in
        THREAD_CFLAGS="-pthread"
        PC_LIBS_PRIVATE="-Wl,-framework,IOKit -Wl,-framework,CoreFoundation -Wl,-prebind -no-undefined -pthread"
        AM_LDFLAGS=${PC_LIBS_PRIVATE}
+       AC_CHECK_HEADERS([poll.h])
+       AC_CHECK_TYPE([nfds_t],
+               [AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])],
+               [AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
+               [#include <poll.h>])
 ;;
 *-mingw*)
        AC_DEFINE(OS_WINDOWS, [], [Windows backend])
@@ -72,6 +79,7 @@ case $host in
        # -avoid-version to avoid a naming scheme such as libusb-0.dll
        AM_LDFLAGS="-no-undefined -avoid-version --add-stdcall-alias"
        AC_CHECK_TOOL(RC, windres, no)
+       AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
        ;;
 *-cygwin*)
        AC_DEFINE(OS_WINDOWS, [], [Windows backend])
@@ -84,6 +92,7 @@ case $host in
        LIBS="${LIBS} ${PC_LIBS_PRIVATE}"
        AM_LDFLAGS="-no-undefined -avoid-version"
        AC_CHECK_TOOL(RC, windres, no)
+       AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])
        ;;
 *)
        AC_MSG_ERROR([unsupported operating system])
index 2856324..dd56857 100644 (file)
@@ -1793,7 +1793,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
 {
        int r;
        struct usbi_pollfd *ipollfd;
-       nfds_t nfds = 0;
+       POLL_NFDS_TYPE nfds = 0;
        struct pollfd *fds;
        int i = -1;
        int timeout_ms;
index 974b108..d21dc86 100644 (file)
@@ -26,6 +26,9 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <time.h>
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
 
 #include <libusb.h>
 
@@ -193,6 +196,7 @@ static inline void usbi_dbg(const char *format, ...)
 #endif
 
 #if defined(OS_LINUX) || defined(OS_DARWIN)
+#include <unistd.h>
 #include <os/poll_posix.h>
 #elif defined(OS_WINDOWS)
 #include <os/poll_windows.h>
@@ -828,7 +832,7 @@ struct usbi_os_backend {
         * Return 0 on success, or a LIBUSB_ERROR code on failure.
         */
        int (*handle_events)(struct libusb_context *ctx,
-               struct pollfd *fds, nfds_t nfds, int num_ready);
+               struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready);
 
        /* Get time from specified clock. At least two clocks must be implemented
           by the backend: USBI_CLOCK_REALTIME, and USBI_CLOCK_MONOTONIC.
index 858a852..4bd13d4 100644 (file)
@@ -1447,7 +1447,7 @@ static void darwin_handle_callback (struct usbi_transfer *itransfer, kern_return
   usbi_handle_transfer_completion (itransfer, darwin_transfer_status (itransfer, result));
 }
 
-static int op_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds, int num_ready) {
+static int op_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready) {
   struct usbi_transfer *itransfer;
   UInt32 io_size;
   IOReturn kresult;
index 44d705d..72db57a 100644 (file)
@@ -2084,7 +2084,7 @@ static int reap_for_handle(struct libusb_device_handle *handle)
 }
 
 static int op_handle_events(struct libusb_context *ctx,
-       struct pollfd *fds, nfds_t nfds, int num_ready)
+       struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready)
 {
        int r;
        int i = 0;
index 17298a5..f8c9e21 100644 (file)
@@ -1,8 +1,6 @@
 #ifndef __LIBUSB_POLL_POSIX_H__
 #define __LIBUSB_POLL_POSIX_H__
 
-#include <unistd.h>
-#include <poll.h>
 #define usbi_write write
 #define usbi_read read
 #define usbi_close close
index a9e3e90..a4d599d 100644 (file)
@@ -61,8 +61,6 @@ struct pollfd {
     short revents;    /* returned events */
 };
 
-typedef unsigned int nfds_t;
-
 // access modes
 enum rw_type {
        RW_NONE,
index e37932a..e19693e 100644 (file)
@@ -2054,10 +2054,10 @@ static void windows_handle_callback (struct usbi_transfer *itransfer, uint32_t i
        }
 }
 
-static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds, int num_ready)
+static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready)
 {
        struct windows_transfer_priv* transfer_priv = NULL;
-       nfds_t i = 0;
+       POLL_NFDS_TYPE i = 0;
        bool found = false;
        struct usbi_transfer *transfer;
        DWORD io_size, io_result;