summaryrefslogtreecommitdiff
path: root/libusb/os
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 /libusb/os
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>
Diffstat (limited to 'libusb/os')
-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
10 files changed, 51 insertions, 84 deletions
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