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.
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])
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])
# -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])
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])
{
int r;
struct usbi_pollfd *ipollfd;
- nfds_t nfds = 0;
+ POLL_NFDS_TYPE nfds = 0;
struct pollfd *fds;
int i = -1;
int timeout_ms;
#include <stddef.h>
#include <stdint.h>
#include <time.h>
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
#include <libusb.h>
#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>
* 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.
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;
}
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;
#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
short revents; /* returned events */
};
-typedef unsigned int nfds_t;
-
// access modes
enum rw_type {
RW_NONE,
}
}
-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;