summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-01-14 01:34:40 +0000
committerPete Batard <pbatard@gmail.com>2010-01-14 01:34:40 +0000
commit71613013b9e7329b4e49047abdee40fea718eb96 (patch)
treeb8181552af39d2bef19b73fe232da34912eac918
parenta32c101a47825f3c523081137d972a619a359d34 (diff)
downloadlibusb-71613013b9e7329b4e49047abdee40fea718eb96.tar.gz
svn r54: - fixes missing config_msvc.h
-rw-r--r--config_msvc.h49
-rw-r--r--examples/lsusb.c3
-rw-r--r--examples/xusb.c12
-rw-r--r--libusb/core.c14
-rw-r--r--libusb/io.c28
-rw-r--r--libusb/libusb.h41
-rw-r--r--libusb/libusbi.h40
-rw-r--r--libusb/os/windows_compat.c11
-rw-r--r--libusb/os/windows_compat.h14
-rw-r--r--libusb/os/windows_usb.c40
-rw-r--r--libusb/os/windows_usb.h8
-rw-r--r--libusb/sync.c4
12 files changed, 178 insertions, 86 deletions
diff --git a/config_msvc.h b/config_msvc.h
new file mode 100644
index 0000000..77fe89b
--- /dev/null
+++ b/config_msvc.h
@@ -0,0 +1,49 @@
+/* config_msvc.h. Manual config.h for MSVC. */
+
+/* Default visibility */
+#define API_EXPORTED /**/
+
+/* Debug message logging */
+#define ENABLE_DEBUG_LOGGING 1
+
+/* Message logging */
+#define ENABLE_LOGGING 1
+
+/* Windows backend */
+#define OS_WINDOWS /**/
+
+/* Name of package */
+#define PACKAGE "libusb"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libusb"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libusb 1.0.5"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libusb"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.0.5"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Backend handles timeout */
+/* #undef USBI_OS_HANDLES_TIMEOUT */
+
+/* timerfd headers available */
+/* #undef USBI_TIMERFD_AVAILABLE */
+
+/* Version number of package */
+#define VERSION "1.0.5"
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
diff --git a/examples/lsusb.c b/examples/lsusb.c
index 317adf0..43806de 100644
--- a/examples/lsusb.c
+++ b/examples/lsusb.c
@@ -44,8 +44,7 @@ static void print_devs(libusb_device **devs)
int main(void)
{
libusb_device **devs;
- int r;
- ssize_t cnt;
+ int r, cnt;
r = libusb_init(NULL);
if (r < 0)
diff --git a/examples/xusb.c b/examples/xusb.c
index 0157f24..080e468 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -20,11 +20,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef _MSC_VER
+#include <config_msvc.h>
+#else
+#include <config.h>
+#endif
#include <stdio.h>
#include <sys/types.h>
#include <inttypes.h>
#include <string.h>
-#include "../config.h"
#include <libusb/libusb.h>
@@ -330,7 +334,8 @@ int test_device(uint16_t vid, uint16_t pid)
int i, j, k, r;
int iface, nb_ifaces;
int test_scsi = 0;
-
+ struct libusb_device_descriptor dev_desc;
+
printf("Opening device...\n");
handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
@@ -341,7 +346,6 @@ int test_device(uint16_t vid, uint16_t pid)
dev = libusb_get_device(handle);
- struct libusb_device_descriptor dev_desc;
printf("reading device descriptor...\n");
CALL_CHECK(libusb_get_device_descriptor(dev, &dev_desc));
printf("length = %d\n", dev_desc.bLength);
@@ -439,7 +443,7 @@ int main(int argc, char** argv)
printf(" -h: display usage\n");
printf(" -j: test OLIMEX ARM-USB-TINY JTAG, 2 channel composite device\n");
printf(" -k: test Generic 2 GB USB Key\n");
- printf(" -x: test Microsoft XBox Controller Type S\n");
+ printf(" -x: test Microsoft XBox Controller Type S (default)\n");
return 0;
}
switch(argv[1][1]) {
diff --git a/libusb/core.c b/libusb/core.c
index dce42ff..535ecf3 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -18,19 +18,22 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef _MSC_VER
+#include <config_msvc.h>
+#else
#include <config.h>
-
+#endif
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
-#include <unistd.h>
#ifdef OS_WINDOWS
#include <windows.h>
#include "os/windows_compat.h"
#else
+#include <unistd.h>
#include <poll.h>
#define write_for_poll write
#define read_for_poll read
@@ -569,7 +572,7 @@ struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
struct libusb_device *ret = NULL;
pthread_mutex_lock(&ctx->usb_devs_lock);
- list_for_each_entry(dev, &ctx->usb_devs, list)
+ list_for_each_entry(dev, &ctx->usb_devs, list, struct libusb_device)
if (dev->session_data == session_id) {
ret = dev;
break;
@@ -599,14 +602,13 @@ struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
* \returns the number of devices in the outputted list, or LIBUSB_ERROR_NO_MEM
* on memory allocation failure.
*/
-API_EXPORTED ssize_t libusb_get_device_list(libusb_context *ctx,
+API_EXPORTED int libusb_get_device_list(libusb_context *ctx,
libusb_device ***list)
{
struct discovered_devs *discdevs = discovered_devs_alloc();
struct libusb_device **ret;
int r = 0;
- size_t i;
- ssize_t len;
+ int i, len;
USBI_GET_CONTEXT(ctx);
usbi_dbg("");
diff --git a/libusb/io.c b/libusb/io.c
index ffc0015..2e59f72 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -18,20 +18,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef _MSC_VER
+#include <config_msvc.h>
+#else
#include <config.h>
+#endif
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#if defined(_MSC_VER)
+#include <time.h>
+#else
#include <sys/time.h>
+#endif
#include <time.h>
-#include <unistd.h>
#ifdef OS_WINDOWS
#include <windows.h>
#include "os/windows_compat.h"
#else
+#include <unistd.h>
#include <poll.h>
#define write_for_poll write
#define read_for_poll read
@@ -1114,7 +1122,7 @@ static int add_to_flying_list(struct usbi_transfer *transfer)
}
/* otherwise, find appropriate place in list */
- list_for_each_entry(cur, &ctx->flying_transfers, list) {
+ list_for_each_entry(cur, &ctx->flying_transfers, list, struct usbi_transfer) {
/* find first timeout that occurs after the transfer in question */
struct timeval *cur_tv = &cur->timeout;
@@ -1714,7 +1722,7 @@ static int handle_timeouts_locked(struct libusb_context *ctx)
/* iterate through flying transfers list, finding all transfers that
* have expired timeouts */
- list_for_each_entry(transfer, &ctx->flying_transfers, list) {
+ list_for_each_entry(transfer, &ctx->flying_transfers, list, struct usbi_transfer) {
struct timeval *cur_tv = &transfer->timeout;
/* if we've reached transfers of infinite timeout, we're all done */
@@ -1785,7 +1793,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
int timeout_ms;
pthread_mutex_lock(&ctx->pollfds_lock);
- list_for_each_entry(ipollfd, &ctx->pollfds, list)
+ list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd)
nfds++;
/* TODO: malloc when number of fd's changes, not on every poll */
@@ -1793,7 +1801,7 @@ static int handle_events(struct libusb_context *ctx, struct timeval *tv)
if (!fds)
return LIBUSB_ERROR_NO_MEM;
- list_for_each_entry(ipollfd, &ctx->pollfds, list) {
+ list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd) {
struct libusb_pollfd *pollfd = &ipollfd->pollfd;
int fd = pollfd->fd;
i++;
@@ -2107,7 +2115,7 @@ API_EXPORTED int libusb_get_next_timeout(libusb_context *ctx,
}
/* find next transfer which hasn't already been processed as timed out */
- list_for_each_entry(transfer, &ctx->flying_transfers, list) {
+ list_for_each_entry(transfer, &ctx->flying_transfers, list, struct usbi_transfer) {
if (!(transfer->flags & USBI_TRANSFER_TIMED_OUT)) {
found = 1;
break;
@@ -2209,7 +2217,7 @@ void usbi_remove_pollfd(struct libusb_context *ctx, int fd)
usbi_dbg("remove fd %d", fd);
pthread_mutex_lock(&ctx->pollfds_lock);
- list_for_each_entry(ipollfd, &ctx->pollfds, list)
+ list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd)
if (ipollfd->pollfd.fd == fd) {
found = 1;
break;
@@ -2249,14 +2257,14 @@ API_EXPORTED const struct libusb_pollfd **libusb_get_pollfds(
USBI_GET_CONTEXT(ctx);
pthread_mutex_lock(&ctx->pollfds_lock);
- list_for_each_entry(ipollfd, &ctx->pollfds, list)
+ list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd)
cnt++;
ret = calloc(cnt + 1, sizeof(struct libusb_pollfd *));
if (!ret)
goto out;
- list_for_each_entry(ipollfd, &ctx->pollfds, list)
+ list_for_each_entry(ipollfd, &ctx->pollfds, list, struct usbi_pollfd)
ret[i++] = (struct libusb_pollfd *) ipollfd;
ret[cnt] = NULL;
@@ -2292,7 +2300,7 @@ void usbi_handle_disconnect(struct libusb_device_handle *handle)
while (1) {
pthread_mutex_lock(&HANDLE_CTX(handle)->flying_transfers_lock);
to_cancel = NULL;
- list_for_each_entry(cur, &HANDLE_CTX(handle)->flying_transfers, list)
+ list_for_each_entry(cur, &HANDLE_CTX(handle)->flying_transfers, list, struct usbi_transfer)
if (__USBI_TRANSFER_TO_LIBUSB_TRANSFER(cur)->dev_handle == handle) {
to_cancel = cur;
break;
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 2dbb9a5..7070898 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -22,7 +22,12 @@
#define __LIBUSB_H__
#include <stdint.h>
+#if defined(_MSC_VER)
+#define inline __inline
+#include <time.h>
+#else
#include <sys/time.h>
+#endif
#include <sys/types.h>
#include <time.h>
#include <limits.h>
@@ -31,24 +36,24 @@
extern "C" {
#endif
-/** \def libusb_cpu_to_le16
- * \ingroup misc
- * Convert a 16-bit value from host-endian to little-endian format. On
- * little endian systems, this function does nothing. On big endian systems,
- * the bytes are swapped.
- * \param x the host-endian value to convert
- * \returns the value in little-endian byte order
+/** \def libusb_cpu_to_le16
+ * \ingroup misc
+ * Convert a 16-bit value from host-endian to little-endian format. On
+ * little endian systems, this function does nothing. On big endian systems,
+ * the bytes are swapped.
+ * \param x the host-endian value to convert
+ * \returns the value in little-endian byte order
*/
-#define libusb_cpu_to_le16(x) ({ \
- union { \
- uint8_t b8[2]; \
- uint16_t b16; \
- } _tmp; \
- uint16_t _tmp2 = (uint16_t)(x); \
- _tmp.b8[1] = _tmp2 >> 8; \
- _tmp.b8[0] = _tmp2 & 0xff; \
- _tmp.b16; \
-})
+static inline uint16_t libusb_cpu_to_le16(uint16_t x) {
+ union {
+ uint8_t b8[2];
+ uint16_t b16;
+ } _tmp;
+ uint16_t _tmp2 = (uint16_t)(x);
+ _tmp.b8[1] = _tmp2 >> 8;
+ _tmp.b8[0] = _tmp2 & 0xff;
+ return _tmp.b16;
+}
/** \def libusb_le16_to_cpu
* \ingroup misc
@@ -769,7 +774,7 @@ int libusb_init(libusb_context **ctx);
void libusb_exit(libusb_context *ctx);
void libusb_set_debug(libusb_context *ctx, int level);
-ssize_t libusb_get_device_list(libusb_context *ctx,
+int libusb_get_device_list(libusb_context *ctx,
libusb_device ***list);
void libusb_free_device_list(libusb_device **list, int unref_devices);
libusb_device *libusb_ref_device(libusb_device *dev);
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 7b0d353..6b501ae 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -21,8 +21,11 @@
#ifndef __LIBUSBI_H__
#define __LIBUSBI_H__
+#ifdef _MSC_VER
+#include <config_msvc.h>
+#else
#include <config.h>
-
+#endif
#include <pthread.h>
#include <stddef.h>
#include <time.h>
@@ -57,17 +60,18 @@ struct list_head {
* pos - A structure pointer has a "member" element
* head - list head
* member - the list_head element in "pos"
+ * type - the type of the first parameter
*/
-#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member); \
+#define list_for_each_entry(pos, head, member, type) \
+ for (pos = list_entry((head)->next, type, member); \
&pos->member != (head); \
- pos = list_entry(pos->member.next, typeof(*pos), member))
+ pos = list_entry(pos->member.next, type, member))
-#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
- n = list_entry(pos->member.next, typeof(*pos), member); \
+#define list_for_each_entry_safe(pos, n, head, member, type) \
+ for (pos = list_entry((head)->next, type, member), \
+ n = list_entry(pos->member.next, type, member); \
&pos->member != (head); \
- pos = n, n = list_entry(n->member.next, typeof(*n), member))
+ pos = n, n = list_entry(n->member.next, type, member))
#define list_empty(entry) ((entry)->next == (entry))
@@ -121,20 +125,20 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level,
const char *function, const char *format, ...);
#ifdef ENABLE_LOGGING
-#define _usbi_log(ctx, level, fmt...) usbi_log(ctx, level, __FUNCTION__, fmt)
+#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__, __VA_ARGS__)
#else
-#define _usbi_log(ctx, level, fmt...)
+#define _usbi_log(ctx, level, ...)
#endif
#ifdef ENABLE_DEBUG_LOGGING
-#define usbi_dbg(fmt...) _usbi_log(NULL, LOG_LEVEL_DEBUG, fmt)
+#define usbi_dbg(...) _usbi_log(NULL, LOG_LEVEL_DEBUG, __VA_ARGS__)
#else
-#define usbi_dbg(fmt...)
+#define usbi_dbg(...)
#endif
-#define usbi_info(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_INFO, fmt)
-#define usbi_warn(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_WARNING, fmt)
-#define usbi_err(ctx, fmt...) _usbi_log(ctx, LOG_LEVEL_ERROR, fmt)
+#define usbi_info(ctx, ...) _usbi_log(ctx, LOG_LEVEL_INFO, __VA_ARGS__)
+#define usbi_warn(ctx, ...) _usbi_log(ctx, LOG_LEVEL_WARNING, __VA_ARGS__)
+#define usbi_err(ctx, ...) _usbi_log(ctx, LOG_LEVEL_ERROR, __VA_ARGS__)
#define USBI_GET_CONTEXT(ctx) if (!(ctx)) (ctx) = usbi_default_context
#define DEVICE_CTX(dev) ((dev)->ctx)
@@ -271,15 +275,15 @@ struct usbi_transfer {
};
#define __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
- ((struct libusb_transfer *)(((void *)(transfer)) \
+ ((struct libusb_transfer *)(((char *)(transfer)) \
+ sizeof(struct usbi_transfer)))
#define __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
- ((struct usbi_transfer *)(((void *)(transfer)) \
+ ((struct usbi_transfer *)(((char *)(transfer)) \
- sizeof(struct usbi_transfer)))
static inline void *usbi_transfer_get_os_priv(struct usbi_transfer *transfer)
{
- return ((void *)transfer) + sizeof(struct usbi_transfer)
+ return ((char *)transfer) + sizeof(struct usbi_transfer)
+ sizeof(struct libusb_transfer)
+ (transfer->num_iso_packets
* sizeof(struct libusb_iso_packet_descriptor));
diff --git a/libusb/os/windows_compat.c b/libusb/os/windows_compat.c
index ea2455d..56feb15 100644
--- a/libusb/os/windows_compat.c
+++ b/libusb/os/windows_compat.c
@@ -70,12 +70,13 @@
#include <stdio.h>
#include <windows.h>
#include <pthread.h>
+#include <io.h>
#include "windows_compat.h"
// Uncomment to debug the polling layer
//#define DEBUG_WINDOWS_COMPAT
-#ifdef DEBUG_WINDOWS_COMPAT
+#if defined(DEBUG_WINDOWS_COMPAT)
#define printb(...) printf(__VA_ARGS__)
#else
#define printb(...)
@@ -205,7 +206,7 @@ void exit_polling(void)
*
* requires a valid index
*/
-inline void _init_read_marker(int index)
+__inline void _init_read_marker(int index)
{
// Cancel any read operation in progress
CancelIo(poll_fd[index].handle);
@@ -241,7 +242,7 @@ int pipe_for_poll(int filedes[2])
return -1;
}
- sprintf(pipe_name, "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), pipe_number++);
+ _snprintf(pipe_name, sizeof(pipe_name), "\\\\.\\pipe\\libusb%08x%04x", (unsigned)GetCurrentProcessId(), pipe_number++);
// Read end of the pipe
handle[0] = CreateNamedPipeA(pipe_name, PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED,
@@ -476,7 +477,7 @@ struct winfd overlapped_to_winfd(OVERLAPPED* overlapped)
*/
int poll(struct pollfd *fds, unsigned int nfds, int timeout)
{
- int i, index, triggered = 0;
+ unsigned int i, index, triggered = 0;
HANDLE *handles_to_wait_on = malloc(nfds*sizeof(HANDLE));
int *handle_to_index = malloc(nfds*sizeof(int));
DWORD nb_handles_to_wait_on = 0;
@@ -747,7 +748,7 @@ ssize_t read_for_poll(int fd, void *buf, size_t count)
// Read supplementary bytes if needed (blocking)
if (count > 1) {
reset_overlapped(poll_fd[index].overlapped);
- if (!ReadFile(poll_fd[index].handle, buf+1, (DWORD)(count-1), &rd_count, poll_fd[index].overlapped)) {
+ if (!ReadFile(poll_fd[index].handle, (char*)buf+1, (DWORD)(count-1), &rd_count, poll_fd[index].overlapped)) {
if(GetLastError() == ERROR_IO_PENDING) {
if (!GetOverlappedResult(poll_fd[index].handle, poll_fd[index].overlapped, &rd_count, TRUE)) {
// TODO: handle more data!
diff --git a/libusb/os/windows_compat.h b/libusb/os/windows_compat.h
index ad55299..95f8d75 100644
--- a/libusb/os/windows_compat.h
+++ b/libusb/os/windows_compat.h
@@ -26,10 +26,18 @@
*
* This is placed in the .h to limit changes required to the core files
*/
-#ifdef interface
+#if defined(interface)
#undef interface
#endif
+#if !defined(ssize_t)
+#if defined (_WIN64)
+#define ssize_t __int64
+#else
+#define ssize_t long
+#endif
+#endif
+
#define MAX_FDS 256
#define POLLIN 0x0001 /* There is data to read */
@@ -77,13 +85,13 @@ struct winfd fd_to_winfd(int fd);
struct winfd handle_to_winfd(HANDLE handle);
struct winfd overlapped_to_winfd(OVERLAPPED* overlapped);
-#ifndef TIMESPEC_TO_TIMEVAL
+#if !defined(TIMESPEC_TO_TIMEVAL)
#define TIMESPEC_TO_TIMEVAL(tv, ts) { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
}
#endif
-#ifndef timersub
+#if !defined(timersub)
#define timersub(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 34570ab..7e01447 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -17,9 +17,12 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#if defined(_MSC_VER)
+#include <config_msvc.h>
+#else
#include <config.h>
+#endif
#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
@@ -28,15 +31,23 @@
#include <windows.h>
#include <tchar.h>
#include <setupapi.h>
+#if defined(_MSC_VER)
+#include <api/usbiodef.h>
+#include <api/usbioctl.h>
+#if !defined __drv_preferredFunction
+#define __drv_preferredFunction(func,why)
+#endif
+#include <api/cfgmgr32.h>
+#else
#include <ddk/usbiodef.h>
#include <ddk/usbioctl.h>
#include <ddk/cfgmgr32.h>
-#include <largeint.h>
+#endif
#include <inttypes.h>
#include <objbase.h> // for string to GUID conv. requires libole32.a
/* Prevent compilation problems on Windows platforms */
-#ifdef interface
+#if defined(interface)
#undef interface
#endif
@@ -45,12 +56,12 @@
#include "windows_usb.h"
// These GUIDs appear undefined on MinGW32
-#ifndef GUID_DEVINTERFACE_USB_HOST_CONTROLLER
+#if !defined(GUID_DEVINTERFACE_USB_HOST_CONTROLLER)
// http://msdn.microsoft.com/en-us/library/bb663109.aspx
const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
#endif
-#ifndef GUID_DEVINTERFACE_USB_DEVICE
+#if !defined(GUID_DEVINTERFACE_USB_DEVICE)
// http://msdn.microsoft.com/en-us/library/bb663093.aspx
const GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED} };
#endif
@@ -151,8 +162,7 @@ static char err_string[ERR_BUFFER_SIZE];
static char* sanitize_path(const char* path)
{
const char root_prefix[] = "\\\\.\\";
- int j;
- size_t size, root_size;
+ size_t j, size, root_size;
char* ret_path = NULL;
int add_root = 0;
@@ -702,7 +712,7 @@ static int usb_enumerate_hub(struct libusb_context *ctx, struct discovered_devs
if (conn_info.DeviceAddress > LIBUSB_DEVADDR_MAX) {
LOOP_CONTINUE("program assertion failed - device address is greater than 255, ignoring device");
} else {
- devaddr = conn_info.DeviceAddress;
+ devaddr = (uint8_t)conn_info.DeviceAddress;
}
// Same trick as linux for session_id, with same caveat
session_id = busnum << (sizeof(libusb_devaddr_t)*8) | devaddr;
@@ -1483,7 +1493,7 @@ 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)
{
struct windows_transfer_priv* transfer_priv = NULL;
- int i = 0;
+ nfds_t i = 0;
bool found = false;
struct usbi_transfer *transfer;
DWORD io_size, io_result;
@@ -1501,7 +1511,7 @@ static int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds,
// Because a Windows OVERLAPPED is used for poll emulation,
// a pollable fd is created and stored with each transfer
- list_for_each_entry(transfer, &ctx->flying_transfers, list) {
+ list_for_each_entry(transfer, &ctx->flying_transfers, list, struct usbi_transfer) {
transfer_priv = usbi_transfer_get_os_priv(transfer);
if (transfer_priv->pollable_fd.fd == fds[i].fd) {
found = true;
@@ -1543,8 +1553,8 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp)
// If hires_frequency is set, we have an hires monotonic timer available
if ((hires_frequency != 0) && (QueryPerformanceCounter(&hires_counter) != 0))
{
- tp->tv_sec = hires_counter.QuadPart / hires_frequency;
- tp->tv_nsec = ((hires_counter.QuadPart % hires_frequency)/1000) * hires_ticks_to_ps;
+ tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
+ tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency)/1000) * hires_ticks_to_ps);
return LIBUSB_SUCCESS;
}
// make sure we fall through to real-time if we can't get hires timer
@@ -1557,8 +1567,8 @@ static int windows_clock_gettime(int clk_id, struct timespec *tp)
rtime.LowPart = ftime.dwLowDateTime;
rtime.HighPart = ftime.dwHighDateTime;
rtime.QuadPart -= epoch_time;
- tp->tv_sec = rtime.QuadPart / 10000000;
- tp->tv_nsec = (rtime.QuadPart % 10000000)*100;
+ tp->tv_sec = (long)(rtime.QuadPart / 10000000);
+ tp->tv_nsec = (long)((rtime.QuadPart % 10000000)*100);
return LIBUSB_SUCCESS;
default:
return LIBUSB_ERROR_INVALID_PARAM;
@@ -1603,7 +1613,7 @@ const struct usbi_os_backend windows_backend = {
windows_handle_events,
windows_clock_gettime,
-#ifdef USBI_TIMERFD_AVAILABLE
+#if defined(USBI_TIMERFD_AVAILABLE)
NULL,
#endif
sizeof(struct windows_device_priv),
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index 55c8bdc..1452224 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -236,7 +236,7 @@ typedef struct _USB_CONFIGURATION_DESCRIPTOR_SHORT {
} USB_CONFIGURATION_DESCRIPTOR_SHORT;
#pragma pack(pop)
-#ifndef USB_HUB_CAP_FLAGS
+#if !defined(_MSC_VER)
typedef union _USB_HUB_CAP_FLAGS {
ULONG ul;
struct {
@@ -249,19 +249,17 @@ typedef union _USB_HUB_CAP_FLAGS {
ULONG ReservedMBZ:26;
};
} USB_HUB_CAP_FLAGS, *PUSB_HUB_CAP_FLAGS;
-#endif
-#ifndef USB_HUB_CAPABILITIES_EX
typedef struct _USB_HUB_CAPABILITIES_EX {
USB_HUB_CAP_FLAGS CapabilityFlags;
} USB_HUB_CAPABILITIES_EX, *PUSB_HUB_CAPABILITIES_EX;
#endif
-#ifndef USB_GET_HUB_CAPABILITIES_EX
+#if !defined(USB_GET_HUB_CAPABILITIES_EX)
#define USB_GET_HUB_CAPABILITIES_EX 276
#endif
-#ifndef IOCTL_USB_GET_HUB_CAPABILITIES_EX
+#if !defined(IOCTL_USB_GET_HUB_CAPABILITIES_EX)
#define IOCTL_USB_GET_HUB_CAPABILITIES_EX \
CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, \
METHOD_BUFFERED, FILE_ANY_ACCESS )
diff --git a/libusb/sync.c b/libusb/sync.c
index bd4d970..75b7af7 100644
--- a/libusb/sync.c
+++ b/libusb/sync.c
@@ -17,7 +17,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef _MSC_VER
+#include <config_msvc.h>
+#else
#include <config.h>
+#endif
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>