diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-01-22 17:39:14 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2020-01-24 11:22:49 -0800 |
commit | d5bb64b3dc438a0a03c66d08a7fd12de5543f538 (patch) | |
tree | db651da15f518b5cb0ab260bfab85c326586c931 /libusb/os | |
parent | 21a163a3954a0f8ae647283f48215e3e3c8caaa2 (diff) | |
download | libusb-d5bb64b3dc438a0a03c66d08a7fd12de5543f538.tar.gz |
configure.ac: Cleanup and refactoring
Make the formatting consistent across the entire file. In particular:
- Always quote strings whose values are derived
- Use tabs consistently
- Wrap all arguments with square brackets
Replace the use of '-a' with '&&' to be more portable.
Rearrange some of the feature checks to be conditional upon the platform
or backend. For example, there is no need to check for nfds_t on Windows
because poll() doesn't exist there. Similarly we now only check for
timerfd on Linux and Solaris. This translates into slightly faster
configure times.
Explicitly define tokens for both the poll and thread implementations.
This makes the preprocessor conditionals much nicer since it is not
necessary to enumerate all possible OS_* tokens. Also replace
POLL_NFDS_TYPE with a proper typedef that is based on the availability
of the nfds_t type.
Migrate to config definition names that are more consistent with
autoconf. The check for timerfd actually verifies the presence of the
library function instead of just the header definitions, and the token
USBI_TIMERFD_AVAILABLE is now HAVE_TIMERFD. Similarly the check for
syslog results in a definition of HAVE_SYSLOG.
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
Diffstat (limited to 'libusb/os')
-rw-r--r-- | libusb/os/linux_usbfs.c | 28 | ||||
-rw-r--r-- | libusb/os/poll_posix.h | 6 | ||||
-rw-r--r-- | libusb/os/poll_windows.c | 4 | ||||
-rw-r--r-- | libusb/os/poll_windows.h | 4 | ||||
-rw-r--r-- | libusb/os/sunos_usb.c | 4 | ||||
-rw-r--r-- | libusb/os/windows_common.c | 4 |
6 files changed, 29 insertions, 21 deletions
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 1b73fde..33affb0 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -145,7 +145,7 @@ static int linux_scan_devices(struct libusb_context *ctx); static int sysfs_scan_device(struct libusb_context *ctx, const char *devname); static int detach_kernel_driver_and_claim(struct libusb_device_handle *, int); -#if !defined(USE_UDEV) +#if !defined(HAVE_LIBUDEV) static int linux_default_scan_devices (struct libusb_context *ctx); #endif @@ -344,7 +344,7 @@ static const char *find_usbfs_path(void) * simply assume /dev/bus/usb rather then making libusb_init fail. * Make the same assumption for Android where SELinux policies might block us * from reading /dev on newer devices. */ -#if defined(USE_UDEV) || defined(__ANDROID__) +#if defined(HAVE_LIBUDEV) || defined(__ANDROID__) if (ret == NULL) ret = "/dev/bus/usb"; #endif @@ -532,7 +532,7 @@ static void op_exit(struct libusb_context *ctx) static int linux_start_event_monitor(void) { -#if defined(USE_UDEV) +#if defined(HAVE_LIBUDEV) return linux_udev_start_event_monitor(); #elif !defined(__ANDROID__) return linux_netlink_start_event_monitor(); @@ -543,7 +543,7 @@ static int linux_start_event_monitor(void) static int linux_stop_event_monitor(void) { -#if defined(USE_UDEV) +#if defined(HAVE_LIBUDEV) return linux_udev_stop_event_monitor(); #elif !defined(__ANDROID__) return linux_netlink_stop_event_monitor(); @@ -558,7 +558,7 @@ static int linux_scan_devices(struct libusb_context *ctx) usbi_mutex_static_lock(&linux_hotplug_lock); -#if defined(USE_UDEV) +#if defined(HAVE_LIBUDEV) ret = linux_udev_scan_devices(ctx); #else ret = linux_default_scan_devices(ctx); @@ -571,7 +571,7 @@ static int linux_scan_devices(struct libusb_context *ctx) static void op_hotplug_poll(void) { -#if defined(USE_UDEV) +#if defined(HAVE_LIBUDEV) linux_udev_hotplug_poll(); #elif !defined(__ANDROID__) linux_netlink_hotplug_poll(); @@ -1229,7 +1229,7 @@ void linux_device_disconnected(uint8_t busnum, uint8_t devaddr) usbi_mutex_static_unlock(&active_contexts_lock); } -#if !defined(USE_UDEV) +#if !defined(HAVE_LIBUDEV) /* open a bus directory and adds all discovered devices to the context */ static int usbfs_scan_busdir(struct libusb_context *ctx, uint8_t busnum) { @@ -1332,7 +1332,7 @@ static int sysfs_scan_device(struct libusb_context *ctx, const char *devname) devname); } -#if !defined(USE_UDEV) +#if !defined(HAVE_LIBUDEV) static int sysfs_get_device_list(struct libusb_context *ctx) { DIR *devices = opendir(SYSFS_DEVICE_PATH); @@ -2760,14 +2760,14 @@ static int reap_for_handle(struct libusb_device_handle *handle) } static int op_handle_events(struct libusb_context *ctx, - struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready) + struct pollfd *fds, usbi_nfds_t nfds, int num_ready) { + usbi_nfds_t n; int r; - unsigned int i = 0; usbi_mutex_lock(&ctx->open_devs_lock); - for (i = 0; i < nfds && num_ready > 0; i++) { - struct pollfd *pollfd = &fds[i]; + for (n = 0; n < nfds && num_ready > 0; n++) { + struct pollfd *pollfd = &fds[n]; struct libusb_device_handle *handle; struct linux_device_handle_priv *hpriv = NULL; @@ -2839,7 +2839,7 @@ static int op_clock_gettime(int clk_id, struct timespec *tp) } } -#ifdef USBI_TIMERFD_AVAILABLE +#ifdef HAVE_TIMERFD static clockid_t op_get_timerfd_clockid(void) { return monotonic_clkid; @@ -2890,7 +2890,7 @@ const struct usbi_os_backend usbi_backend = { .clock_gettime = op_clock_gettime, -#ifdef USBI_TIMERFD_AVAILABLE +#ifdef HAVE_TIMERFD .get_timerfd_clockid = op_get_timerfd_clockid, #endif diff --git a/libusb/os/poll_posix.h b/libusb/os/poll_posix.h index 01702f3..48c4904 100644 --- a/libusb/os/poll_posix.h +++ b/libusb/os/poll_posix.h @@ -4,6 +4,12 @@ #include <poll.h> #include <unistd.h> +#ifdef HAVE_NFDS_T +typedef nfds_t usbi_nfds_t; +#else +typedef unsigned int usbi_nfds_t; +#endif + #define usbi_write write #define usbi_read read #define usbi_close close diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c index 21a1363..bd8ac67 100644 --- a/libusb/os/poll_windows.c +++ b/libusb/os/poll_windows.c @@ -334,12 +334,12 @@ static DWORD poll_wait(const HANDLE *wait_handles, DWORD num_wait_handles, DWORD * Currently, this function only accepts one of POLLIN or POLLOUT per fd * (but you can create multiple fds from the same handle for read and write) */ -int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout) +int usbi_poll(struct pollfd *fds, usbi_nfds_t nfds, int timeout) { struct file_descriptor **fds_array; HANDLE *handles_array; struct file_descriptor *fd; - unsigned int n; + usbi_nfds_t n; int nready; if (nfds <= MAXIMUM_WAIT_OBJECTS) { diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h index 7decd4a..c78c9d3 100644 --- a/libusb/os/poll_windows.h +++ b/libusb/os/poll_windows.h @@ -41,6 +41,8 @@ #define POLLHUP 0x0010 /* Hung up */ #define POLLNVAL 0x0020 /* Invalid request: fd not open */ +typedef unsigned int usbi_nfds_t; + struct pollfd { int fd; /* file descriptor */ short events; /* requested events */ @@ -57,7 +59,7 @@ extern const struct winfd INVALID_WINFD; struct winfd usbi_create_fd(void); int usbi_pipe(int pipefd[2]); -int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout); +int usbi_poll(struct pollfd *fds, usbi_nfds_t nfds, int timeout); ssize_t usbi_write(int fd, const void *buf, size_t count); ssize_t usbi_read(int fd, void *buf, size_t count); int usbi_close(int fd); diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c index 9d42b8a..85d0fdf 100644 --- a/libusb/os/sunos_usb.c +++ b/libusb/os/sunos_usb.c @@ -1641,7 +1641,7 @@ sunos_usb_get_status(int fd) return (status); } -#ifdef USBI_TIMERFD_AVAILABLE +#ifdef HAVE_TIMERFD static clockid_t op_get_timerfd_clockid(void) { return CLOCK_MONOTONIC; @@ -1672,7 +1672,7 @@ const struct usbi_os_backend usbi_backend = { .cancel_transfer = sunos_cancel_transfer, .handle_transfer_completion = sunos_handle_transfer_completion, .clock_gettime = sunos_clock_gettime, -#ifdef USBI_TIMERFD_AVAILABLE +#ifdef HAVE_TIMERFD .get_timerfd_clockid = op_get_timerfd_clockid, #endif .device_priv_size = sizeof(sunos_dev_priv_t), diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c index a8ee237..df05eaf 100644 --- a/libusb/os/windows_common.c +++ b/libusb/os/windows_common.c @@ -678,12 +678,12 @@ static int windows_cancel_transfer(struct usbi_transfer *itransfer) return priv->backend->cancel_transfer(itransfer); } -static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready) +static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, usbi_nfds_t nfds, int num_ready) { struct windows_context_priv *priv = _context_priv(ctx); struct usbi_transfer *itransfer; DWORD io_size, io_result; - POLL_NFDS_TYPE i; + usbi_nfds_t i; bool found; int transfer_fd; int r = LIBUSB_SUCCESS; |