summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2020-01-22 15:53:17 -0800
committerChris Dickens <christopher.a.dickens@gmail.com>2020-01-24 11:21:27 -0800
commitaaff15d48d1b8555aabf012b06bf39bf8aa4768a (patch)
tree1eebfa64f672df87806852b00afb2b924b4b5eae
parent325e5ac8ddf2cb100a47e39185bc9f134d3b2f98 (diff)
downloadlibusb-aaff15d48d1b8555aabf012b06bf39bf8aa4768a.tar.gz
Misc: Trim and consolidate header file usage
Refactor libusbi.h to include the set of common header files needed by every main source file in the library and change these source files to include libusbi.h first, followed by any non-common headers. Including libusbi.h first ensures that the config definitions are pulled in and will eliminate redundant includes in the individual sources files. Also clean up some whitespace errors and remove unnecessary definitions in the manually generated config.h files. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--Xcode/config.h3
-rw-r--r--android/config.h48
-rw-r--r--libusb/core.c22
-rw-r--r--libusb/descriptor.c7
-rw-r--r--libusb/hotplug.c13
-rw-r--r--libusb/hotplug.h4
-rw-r--r--libusb/io.c16
-rw-r--r--libusb/libusb.h19
-rw-r--r--libusb/libusbi.h121
-rw-r--r--libusb/os/darwin_usb.c2
-rw-r--r--libusb/os/linux_netlink.c14
-rw-r--r--libusb/os/linux_udev.c19
-rw-r--r--libusb/os/poll_posix.c9
-rw-r--r--libusb/os/poll_posix.h11
-rw-r--r--libusb/os/poll_windows.h50
-rw-r--r--libusb/os/threads_posix.c15
-rw-r--r--libusb/os/threads_posix.h7
-rw-r--r--libusb/os/threads_windows.c6
-rw-r--r--libusb/os/threads_windows.h2
-rw-r--r--libusb/strerror.c10
-rw-r--r--libusb/sync.c7
-rw-r--r--libusb/version_nano.h2
-rw-r--r--msvc/config.h19
23 files changed, 149 insertions, 277 deletions
diff --git a/Xcode/config.h b/Xcode/config.h
index 14d1527..c280d9f 100644
--- a/Xcode/config.h
+++ b/Xcode/config.h
@@ -6,9 +6,6 @@
/* Message logging */
#define ENABLE_LOGGING 1
-/* Define to 1 if you have the <poll.h> header file. */
-#define HAVE_POLL_H 1
-
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
diff --git a/android/config.h b/android/config.h
index 0dd35e2..e880d1e 100644
--- a/android/config.h
+++ b/android/config.h
@@ -17,59 +17,29 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/* Default visibility */
+#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
+
/* Start with debug message logging enabled */
/* #undef ENABLE_DEBUG_LOGGING */
/* Message logging */
#define ENABLE_LOGGING
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
+/* Define to 1 if you have the <asm/types.h> header file. */
+#define HAVE_ASM_TYPES_H 1
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
+/* Define to 1 if you have the <sys/time.h> header file. */
+#define HAVE_SYS_TIME_H 1
/* Linux backend */
#define OS_LINUX 1
-/* Enable output to system log */
-#define USE_SYSTEM_LOGGING_FACILITY 1
-
/* type of second poll() argument */
#define POLL_NFDS_TYPE nfds_t
/* Use POSIX Threads */
#define THREADS_POSIX 1
-/* Default visibility */
-#define DEFAULT_VISIBILITY __attribute__((visibility("default")))
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define to 1 if you have the <poll.h> header file. */
-#define HAVE_POLL_H 1
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/time.h> header file. */
-#define HAVE_SYS_TIME_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if you have the <linux/filter.h> header file. */
-#define HAVE_LINUX_FILTER_H 1
-
-/* Define to 1 if you have the <linux/netlink.h> header file. */
-#define HAVE_LINUX_NETLINK_H 1
-
-/* Define to 1 if you have the <asm/types.h> header file. */
-#define HAVE_ASM_TYPES_H 1
-
-/* Define to 1 if you have the <sys/socket.h> header file. */
-#define HAVE_SYS_SOCKET_H 1
+/* Enable output to system log */
+#define USE_SYSTEM_LOGGING_FACILITY 1
diff --git a/libusb/core.c b/libusb/core.c
index 26df871..bf68984 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -20,30 +20,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "config.h"
+#include "libusbi.h"
+#include "hotplug.h"
-#include <errno.h>
-#include <stdarg.h>
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
-#ifdef __ANDROID__
-#include <android/log.h>
-#endif
-
-#include "libusbi.h"
-#include "hotplug.h"
-
struct libusb_context *usbi_default_context = NULL;
static const struct libusb_version libusb_version_internal =
{ LIBUSB_MAJOR, LIBUSB_MINOR, LIBUSB_MICRO, LIBUSB_NANO,
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index 53d1f6f..4c7733d 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -19,15 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
#include <string.h>
-#include "libusbi.h"
-
#define DESC_HEADER_LENGTH 2
#define DEVICE_DESC_LENGTH 18
#define CONFIG_DESC_LENGTH 9
diff --git a/libusb/hotplug.c b/libusb/hotplug.c
index 3ccdc2f..71ec3fb 100644
--- a/libusb/hotplug.c
+++ b/libusb/hotplug.c
@@ -19,17 +19,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#include <assert.h>
-
#include "libusbi.h"
#include "hotplug.h"
@@ -48,7 +37,7 @@
* Version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102, has added support
* for hotplug events on <b>some</b> platforms (you should test if your platform
* supports hotplug notification by calling \ref libusb_has_capability() with
- * parameter \ref LIBUSB_CAP_HAS_HOTPLUG).
+ * parameter \ref LIBUSB_CAP_HAS_HOTPLUG).
*
* This interface allows you to request notification for the arrival and departure
* of matching USB devices.
diff --git a/libusb/hotplug.h b/libusb/hotplug.h
index 75b2695..4335fbe 100644
--- a/libusb/hotplug.h
+++ b/libusb/hotplug.h
@@ -92,8 +92,8 @@ struct libusb_hotplug_message {
void usbi_hotplug_deregister(struct libusb_context *ctx, int forced);
void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
- libusb_hotplug_event event);
+ libusb_hotplug_event event);
void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
- libusb_hotplug_event event);
+ libusb_hotplug_event event);
#endif
diff --git a/libusb/io.c b/libusb/io.c
index 0c7ef6c..af6c1ae 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -21,25 +21,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
+#include "hotplug.h"
-#include <assert.h>
#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#ifdef USBI_TIMERFD_AVAILABLE
-#include <unistd.h>
#include <sys/timerfd.h>
+#include <unistd.h>
#endif
-#include "libusbi.h"
-#include "hotplug.h"
-
/**
* \page libusb_io Synchronous and asynchronous device I/O
*
diff --git a/libusb/libusb.h b/libusb/libusb.h
index f066232..2c4d589 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -1941,9 +1941,7 @@ typedef enum {
* returning 1 will cause this callback to be deregistered
*/
typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
- libusb_device *device,
- libusb_hotplug_event event,
- void *user_data);
+ libusb_device *device, libusb_hotplug_event event, void *user_data);
/** \ingroup libusb_hotplug
* Register a hotplug callback function
@@ -1980,13 +1978,10 @@ typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
* \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure
*/
int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
- libusb_hotplug_event events,
- libusb_hotplug_flag flags,
- int vendor_id, int product_id,
- int dev_class,
- libusb_hotplug_callback_fn cb_fn,
- void *user_data,
- libusb_hotplug_callback_handle *callback_handle);
+ libusb_hotplug_event events, libusb_hotplug_flag flags,
+ int vendor_id, int product_id, int dev_class,
+ libusb_hotplug_callback_fn cb_fn, void *user_data,
+ libusb_hotplug_callback_handle *callback_handle);
/** \ingroup libusb_hotplug
* Deregisters a hotplug callback.
@@ -2000,7 +1995,7 @@ int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
* \param[in] callback_handle the handle of the callback to deregister
*/
void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
- libusb_hotplug_callback_handle callback_handle);
+ libusb_hotplug_callback_handle callback_handle);
/** \ingroup libusb_hotplug
* Gets the user_data associated with a hotplug callback.
@@ -2011,7 +2006,7 @@ void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
* \param[in] callback_handle the handle of the callback to get the user_data of
*/
void * LIBUSB_CALL libusb_hotplug_get_user_data(struct libusb_context *ctx,
- libusb_hotplug_callback_handle callback_handle);
+ libusb_hotplug_callback_handle callback_handle);
/** \ingroup libusb_lib
* Available option values for libusb_set_option().
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 2c574d3..c31b49b 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -4,6 +4,7 @@
* Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
* Copyright © 2019 Nathan Hjelm <hjelmn@cs.umm.edu>
* Copyright © 2019 Google LLC. All rights reserved.
+ * Copyright © 2020 Chris Dickens <christopher.a.dickens@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -25,19 +26,41 @@
#include <config.h>
-#include <stdlib.h>
#include <assert.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <time.h>
#include <stdarg.h>
-#ifdef HAVE_POLL_H
-#include <poll.h>
+#include <stddef.h>
+#include <stdlib.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
#endif
#include "libusb.h"
#include "version.h"
+#ifndef ARRAYSIZE
+#define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
+#endif
+
+#ifndef CLAMP
+#define CLAMP(val, min, max) \
+ ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
+#endif
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+/* The following is used to silence warnings for unused variables */
+#if defined(UNREFERENCED_PARAMETER)
+#define UNUSED(var) UNREFERENCED_PARAMETER(var)
+#else
+#define UNUSED(var) do { (void)(var); } while(0)
+#endif
+
/* Attribute to ensure that a structure member is aligned to a natural
* pointer alignment. Used for os_priv member. */
#if defined(_MSC_VER)
@@ -52,6 +75,21 @@
#define PTR_ALIGNED
#endif
+/* Internal abstraction for poll */
+#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) || \
+ defined(OS_HAIKU) || defined(OS_SUNOS) || defined(OS_NULL)
+#include "os/poll_posix.h"
+#elif defined(OS_WINDOWS)
+#include "os/poll_windows.h"
+#endif
+
+/* Internal abstraction for thread synchronization */
+#if defined(THREADS_POSIX)
+#include "os/threads_posix.h"
+#elif defined(OS_WINDOWS)
+#include "os/threads_windows.h"
+#endif
+
/* Inside the libusb code, mark all public functions as follows:
* return_type API_EXPORTED function_name(params) { ... }
* But if the function returns a pointer, mark it as follows:
@@ -90,17 +128,6 @@ extern "C" {
/* Terminator for log lines */
#define USBI_LOG_LINE_END "\n"
-/* The following is used to silence warnings for unused variables */
-#if defined(UNREFERENCED_PARAMETER)
-#define UNUSED(var) UNREFERENCED_PARAMETER(var)
-#else
-#define UNUSED(var) do { (void)(var); } while(0)
-#endif
-
-#if !defined(ARRAYSIZE)
-#define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
-#endif
-
struct list_head {
struct list_head *prev, *next;
};
@@ -182,25 +209,12 @@ static inline void list_cut(struct list_head *list, struct list_head *head)
static inline void *usbi_reallocf(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
+
if (!ret)
free(ptr);
return ret;
}
-#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *mptr = (ptr); \
- (type *)( (char *)mptr - offsetof(type,member) );})
-
-#ifndef CLAMP
-#define CLAMP(val, min, max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val)))
-#endif
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#endif
-
#define TIMESPEC_IS_SET(ts) ((ts)->tv_sec != 0 || (ts)->tv_nsec != 0)
#if defined(OS_WINDOWS)
@@ -214,7 +228,7 @@ static inline void *usbi_reallocf(void *ptr, size_t size)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
do { \
(tv)->tv_sec = (TIMEVAL_TV_SEC_TYPE) (ts)->tv_sec; \
- (tv)->tv_usec = (ts)->tv_nsec / 1000; \
+ (tv)->tv_usec = (ts)->tv_nsec / 1000L; \
} while (0)
#endif
@@ -236,17 +250,17 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__, __VA_ARGS__)
-#define usbi_err(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_ERROR, __VA_ARGS__)
-#define usbi_warn(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_WARNING, __VA_ARGS__)
-#define usbi_info(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_INFO, __VA_ARGS__)
-#define usbi_dbg(...) _usbi_log(NULL, LIBUSB_LOG_LEVEL_DEBUG, __VA_ARGS__)
+#define usbi_err(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_ERROR, __VA_ARGS__)
+#define usbi_warn(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_WARNING, __VA_ARGS__)
+#define usbi_info(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_INFO, __VA_ARGS__)
+#define usbi_dbg(...) _usbi_log(NULL, LIBUSB_LOG_LEVEL_DEBUG, __VA_ARGS__)
#else /* ENABLE_LOGGING */
-#define usbi_err(ctx, ...) do { (void)ctx; } while (0)
-#define usbi_warn(ctx, ...) do { (void)ctx; } while (0)
-#define usbi_info(ctx, ...) do { (void)ctx; } while (0)
-#define usbi_dbg(...) do {} while (0)
+#define usbi_err(ctx, ...) UNUSED(ctx)
+#define usbi_warn(ctx, ...) UNUSED(ctx)
+#define usbi_info(ctx, ...) UNUSED(ctx)
+#define usbi_dbg(...) do {} while (0)
#endif /* ENABLE_LOGGING */
@@ -267,18 +281,6 @@ void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
#define IS_XFERIN(xfer) (0 != ((xfer)->endpoint & LIBUSB_ENDPOINT_IN))
#define IS_XFEROUT(xfer) (!IS_XFERIN(xfer))
-/* Internal abstraction for thread synchronization */
-#if defined(THREADS_POSIX)
-#include "os/threads_posix.h"
-#elif defined(OS_WINDOWS)
-#include "os/threads_windows.h"
-#endif
-
-extern struct libusb_context *usbi_default_context;
-
-/* Forward declaration for use in context (fully defined inside poll abstraction) */
-struct pollfd;
-
struct libusb_context {
#if defined(ENABLE_LOGGING) && !defined(ENABLE_DEBUG_LOGGING)
enum libusb_log_level debug;
@@ -545,21 +547,12 @@ int usbi_device_cache_descriptor(libusb_device *dev);
int usbi_get_config_index_by_value(struct libusb_device *dev,
uint8_t bConfigurationValue, int *idx);
-void usbi_connect_device (struct libusb_device *dev);
-void usbi_disconnect_device (struct libusb_device *dev);
+void usbi_connect_device(struct libusb_device *dev);
+void usbi_disconnect_device(struct libusb_device *dev);
int usbi_signal_event(struct libusb_context *ctx);
int usbi_clear_event(struct libusb_context *ctx);
-/* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
-#if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
- defined(OS_HAIKU) || defined(OS_SUNOS) || defined(OS_NULL)
-#include <unistd.h>
-#include "os/poll_posix.h"
-#elif defined(OS_WINDOWS)
-#include "os/poll_windows.h"
-#endif
-
struct usbi_pollfd {
/* must come first */
struct libusb_pollfd pollfd;
@@ -1181,6 +1174,8 @@ extern const struct usbi_os_backend usbi_backend;
extern struct list_head active_contexts_list;
extern usbi_mutex_static_t active_contexts_lock;
+extern struct libusb_context *usbi_default_context;
+
#ifdef __cplusplus
}
#endif
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 7fdf88f..75ab2be 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "config.h"
+#include <config.h>
#include <assert.h>
#include <time.h>
#include <ctype.h>
diff --git a/libusb/os/linux_netlink.c b/libusb/os/linux_netlink.c
index 0ceb951..025ddd5 100644
--- a/libusb/os/linux_netlink.c
+++ b/libusb/os/linux_netlink.c
@@ -21,27 +21,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
+#include "linux_usbfs.h"
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <pthread.h>
#include <string.h>
#include <unistd.h>
-#include <sys/types.h>
#ifdef HAVE_ASM_TYPES_H
#include <asm/types.h>
#endif
-
-#include <sys/socket.h>
#include <linux/netlink.h>
-
-#include "libusbi.h"
-#include "linux_usbfs.h"
+#include <sys/socket.h>
#define NL_GROUP_KERNEL 1
diff --git a/libusb/os/linux_udev.c b/libusb/os/linux_udev.c
index 8cf19d5..d079c79 100644
--- a/libusb/os/linux_udev.c
+++ b/libusb/os/linux_udev.c
@@ -20,27 +20,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
+#include "linux_usbfs.h"
-#include <assert.h>
-#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <libudev.h>
#include <poll.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <pthread.h>
#include <string.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/utsname.h>
-#include <sys/socket.h>
#include <unistd.h>
-#include <libudev.h>
-
-#include "libusbi.h"
-#include "linux_usbfs.h"
/* udev context */
static struct udev *udev_ctx = NULL;
diff --git a/libusb/os/poll_posix.c b/libusb/os/poll_posix.c
index a2ad157..93e9bee 100644
--- a/libusb/os/poll_posix.c
+++ b/libusb/os/poll_posix.c
@@ -18,14 +18,11 @@
*
*/
-#include <config.h>
+#include "libusbi.h"
-#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
-#include <stdlib.h>
-
-#include "libusbi.h"
+#include <fcntl.h>
+#include <unistd.h>
int usbi_pipe(int pipefd[2])
{
diff --git a/libusb/os/poll_posix.h b/libusb/os/poll_posix.h
index 5b4b2c9..01702f3 100644
--- a/libusb/os/poll_posix.h
+++ b/libusb/os/poll_posix.h
@@ -1,10 +1,13 @@
#ifndef LIBUSB_POLL_POSIX_H
#define LIBUSB_POLL_POSIX_H
-#define usbi_write write
-#define usbi_read read
-#define usbi_close close
-#define usbi_poll poll
+#include <poll.h>
+#include <unistd.h>
+
+#define usbi_write write
+#define usbi_read read
+#define usbi_close close
+#define usbi_poll poll
int usbi_pipe(int pipefd[2]);
diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h
index 6c51919..7decd4a 100644
--- a/libusb/os/poll_windows.h
+++ b/libusb/os/poll_windows.h
@@ -21,12 +21,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
-#pragma once
-#if defined(_MSC_VER)
-// disable /W4 MSVC warnings that are benign
-#pragma warning(disable:4127) // conditional expression is constant
-#endif
+#ifndef LIBUSB_POLL_WINDOWS_H
+#define LIBUSB_POLL_WINDOWS_H
// Handle synchronous completion through the overlapped structure
#if !defined(STATUS_REPARSE) // reuse the REPARSE status code
@@ -37,12 +34,12 @@
#define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2)
-#define POLLIN 0x0001 /* There is data to read */
-#define POLLPRI 0x0002 /* There is urgent data to read */
-#define POLLOUT 0x0004 /* Writing now will not block */
-#define POLLERR 0x0008 /* Error condition */
-#define POLLHUP 0x0010 /* Hung up */
-#define POLLNVAL 0x0020 /* Invalid request: fd not open */
+#define POLLIN 0x0001 /* There is data to read */
+#define POLLPRI 0x0002 /* There is urgent data to read */
+#define POLLOUT 0x0004 /* Writing now will not block */
+#define POLLERR 0x0008 /* Error condition */
+#define POLLHUP 0x0010 /* Hung up */
+#define POLLNVAL 0x0020 /* Invalid request: fd not open */
struct pollfd {
int fd; /* file descriptor */
@@ -68,24 +65,23 @@ int usbi_close(int fd);
/*
* Timeval operations
*/
-#if defined(DDKBUILD)
-#include <winsock.h> // defines timeval functions on DDK
-#endif
-
#if !defined(TIMESPEC_TO_TIMEVAL)
-#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
- (tv)->tv_sec = (long)(ts)->tv_sec; \
- (tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \
-}
+#define TIMESPEC_TO_TIMEVAL(tv, ts) \
+do { \
+ (tv)->tv_sec = (long)(ts)->tv_sec; \
+ (tv)->tv_usec = (long)(ts)->tv_nsec / 1000; \
+} while (0)
#endif
#if !defined(timersub)
-#define timersub(a, b, result) \
-do { \
- (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
- (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
- if ((result)->tv_usec < 0) { \
- --(result)->tv_sec; \
- (result)->tv_usec += 1000000; \
- } \
+#define timersub(a, b, result) \
+do { \
+ (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
+ (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
+ if ((result)->tv_usec < 0) { \
+ --(result)->tv_sec; \
+ (result)->tv_usec += 1000000; \
+ } \
} while (0)
#endif
+
+#endif
diff --git a/libusb/os/threads_posix.c b/libusb/os/threads_posix.c
index 16a7578..92bb11d 100644
--- a/libusb/os/threads_posix.c
+++ b/libusb/os/threads_posix.c
@@ -19,24 +19,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
-#include <time.h>
-#if defined(__linux__) || defined(__OpenBSD__)
+#if defined(__ANDROID__)
+# include <unistd.h>
+#elif defined(__linux__) || defined(__OpenBSD__)
# if defined(__OpenBSD__)
# define _BSD_SOURCE
# endif
-# include <unistd.h>
# include <sys/syscall.h>
-#elif defined(__APPLE__)
-# include <pthread.h>
-#elif defined(__CYGWIN__)
-# include <windows.h>
#endif
-#include "threads_posix.h"
-#include "libusbi.h"
-
int usbi_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex, const struct timeval *tv)
{
diff --git a/libusb/os/threads_posix.h b/libusb/os/threads_posix.h
index 9f1ef94..eadb978 100644
--- a/libusb/os/threads_posix.h
+++ b/libusb/os/threads_posix.h
@@ -22,9 +22,6 @@
#define LIBUSB_THREADS_POSIX_H
#include <pthread.h>
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
#define USBI_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t usbi_mutex_static_t;
@@ -64,9 +61,9 @@ static inline void usbi_cond_init(pthread_cond_t *cond)
{
(void)pthread_cond_init(cond, NULL);
}
-static inline int usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
+static inline void usbi_cond_wait(usbi_cond_t *cond, usbi_mutex_t *mutex)
{
- return pthread_cond_wait(cond, mutex);
+ (void)pthread_cond_wait(cond, mutex);
}
int usbi_cond_timedwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, const struct timeval *tv);
diff --git a/libusb/os/threads_windows.c b/libusb/os/threads_windows.c
index 27b1fb5..81f7945 100644
--- a/libusb/os/threads_windows.c
+++ b/libusb/os/threads_windows.c
@@ -19,12 +19,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
#include <errno.h>
-#include "libusbi.h"
-
int usbi_cond_timedwait(usbi_cond_t *cond,
usbi_mutex_t *mutex, const struct timeval *tv)
{
@@ -41,4 +39,4 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
return ETIMEDOUT;
else
return EINVAL;
-} \ No newline at end of file
+}
diff --git a/libusb/os/threads_windows.h b/libusb/os/threads_windows.h
index 3a98df5..9bf8ff4 100644
--- a/libusb/os/threads_windows.h
+++ b/libusb/os/threads_windows.h
@@ -64,7 +64,7 @@ struct timespec {
long tv_sec;
long tv_nsec;
};
-#endif /* HAVE_STRUCT_TIMESPEC | _TIMESPEC_DEFINED */
+#endif /* HAVE_STRUCT_TIMESPEC || _TIMESPEC_DEFINED */
// We *were* getting ETIMEDOUT from pthread.h:
#ifndef ETIMEDOUT
diff --git a/libusb/strerror.c b/libusb/strerror.c
index bae6efd..c74052f 100644
--- a/libusb/strerror.c
+++ b/libusb/strerror.c
@@ -17,22 +17,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
-#include <locale.h>
-#include <stdlib.h>
#include <string.h>
-#if defined(HAVE_STRINGS_H)
+#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
-#include "libusbi.h"
-
#if defined(_MSC_VER)
#define strncasecmp _strnicmp
#endif
-static size_t usbi_locale = 0;
+static size_t usbi_locale;
/** \ingroup libusb_misc
* How to add a new \ref libusb_strerror() translation:
diff --git a/libusb/sync.c b/libusb/sync.c
index 863fe5c..68774c6 100644
--- a/libusb/sync.c
+++ b/libusb/sync.c
@@ -20,15 +20,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <config.h>
+#include "libusbi.h"
-#include <errno.h>
-#include <stdint.h>
-#include <stdlib.h>
#include <string.h>
-#include "libusbi.h"
-
/**
* @defgroup libusb_syncio Synchronous device I/O
*
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 6cb8510..6cb695c 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11440
+#define LIBUSB_NANO 11441
diff --git a/msvc/config.h b/msvc/config.h
index 705b59a..ad3dcaa 100644
--- a/msvc/config.h
+++ b/msvc/config.h
@@ -19,8 +19,6 @@
#pragma warning(disable:4200)
/* Disable: warning C4324: structure was padded due to __declspec(align()) */
#pragma warning(disable:4324)
-/* Disable: warning C6258: Using TerminateThread does not allow proper thread clean up */
-#pragma warning(disable:6258)
/* Disable: warning C4996: 'GetVersionA': was declared deprecated */
#pragma warning(disable:4996)
@@ -34,20 +32,17 @@
/* Default visibility */
#define DEFAULT_VISIBILITY /**/
-/* Enable global message logging */
-#define ENABLE_LOGGING 1
-
/* Uncomment to start with debug message logging enabled */
// #define ENABLE_DEBUG_LOGGING 1
-/* Uncomment to enabling logging to system log */
-// #define USE_SYSTEM_LOGGING_FACILITY
+/* Message logging */
+#define ENABLE_LOGGING 1
+
+/* Windows backend */
+#define OS_WINDOWS 1
/* type of second poll() argument */
#define POLL_NFDS_TYPE unsigned int
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Windows backend */
-#define OS_WINDOWS 1
+/* Uncomment to enabling output to system log */
+// #define USE_SYSTEM_LOGGING_FACILITY