From: Peter Stuge Date: Sat, 30 Oct 2010 20:07:37 +0000 (+0200) Subject: configure.ac: Check for poll.h, and for nfds_t on Darwin X-Git-Tag: upstream/1.0.21~862 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a120747d561929682cd0276ea4c13fb22fad8554;p=platform%2Fupstream%2Flibusb.git configure.ac: Check for poll.h, and for nfds_t on Darwin 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. --- diff --git a/configure.ac b/configure.ac index 3dcb02d..c6515ad 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ]) ;; *-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]) diff --git a/libusb/io.c b/libusb/io.c index 2856324..dd56857 100644 --- a/libusb/io.c +++ b/libusb/io.c @@ -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; diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 974b108..d21dc86 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -26,6 +26,9 @@ #include #include #include +#ifdef HAVE_POLL_H +#include +#endif #include @@ -193,6 +196,7 @@ static inline void usbi_dbg(const char *format, ...) #endif #if defined(OS_LINUX) || defined(OS_DARWIN) +#include #include #elif defined(OS_WINDOWS) #include @@ -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. diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 858a852..4bd13d4 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -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; diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 44d705d..72db57a 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -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; diff --git a/libusb/os/poll_posix.h b/libusb/os/poll_posix.h index 17298a5..f8c9e21 100644 --- a/libusb/os/poll_posix.h +++ b/libusb/os/poll_posix.h @@ -1,8 +1,6 @@ #ifndef __LIBUSB_POLL_POSIX_H__ #define __LIBUSB_POLL_POSIX_H__ -#include -#include #define usbi_write write #define usbi_read read #define usbi_close close diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h index a9e3e90..a4d599d 100644 --- a/libusb/os/poll_windows.h +++ b/libusb/os/poll_windows.h @@ -61,8 +61,6 @@ struct pollfd { short revents; /* returned events */ }; -typedef unsigned int nfds_t; - // access modes enum rw_type { RW_NONE, diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index e37932a..e19693e 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -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;