summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libusb/os/poll_windows.c136
-rw-r--r--libusb/os/windows_usb.c36
2 files changed, 86 insertions, 86 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 8656ea0..ad948f7 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -138,21 +138,21 @@ static volatile LONG compat_spinlock = 0;
// platform headers, we hook into the Kernel32 system DLL directly to seek it.
static BOOL (__stdcall *pCancelIoEx)(HANDLE, LPOVERLAPPED) = NULL;
#define CancelIoEx_Available (pCancelIoEx != NULL)
-__inline BOOL cancel_io(int index)
+__inline BOOL cancel_io(int _index)
{
- if ((index < 0) || (index >= MAX_FDS)) {
+ if ((_index < 0) || (_index >= MAX_FDS)) {
return FALSE;
}
- if ( (poll_fd[index].fd < 0) || (poll_fd[index].handle == INVALID_HANDLE_VALUE)
- || (poll_fd[index].handle == 0) || (poll_fd[index].overlapped == NULL) ) {
+ if ( (poll_fd[_index].fd < 0) || (poll_fd[_index].handle == INVALID_HANDLE_VALUE)
+ || (poll_fd[_index].handle == 0) || (poll_fd[_index].overlapped == NULL) ) {
return TRUE;
}
if (CancelIoEx_Available) {
- return (*pCancelIoEx)(poll_fd[index].handle, poll_fd[index].overlapped);
+ return (*pCancelIoEx)(poll_fd[_index].handle, poll_fd[_index].overlapped);
}
- if (_poll_fd[index].thread_id == GetCurrentThreadId()) {
- return CancelIo(poll_fd[index].handle);
+ if (_poll_fd[_index].thread_id == GetCurrentThreadId()) {
+ return CancelIo(poll_fd[_index].handle);
}
usbi_warn(NULL, "Unable to cancel I/O that was started from another thread");
return FALSE;
@@ -457,25 +457,25 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode)
return INVALID_WINFD;
}
-void _free_index(int index)
+void _free_index(int _index)
{
// Cancel any async IO (Don't care about the validity of our handles for this)
- cancel_io(index);
+ cancel_io(_index);
// close fake handle for devices
- if ( (poll_fd[index].handle != INVALID_HANDLE_VALUE) && (poll_fd[index].handle != 0)
- && (GetFileType(poll_fd[index].handle) == FILE_TYPE_UNKNOWN) ) {
- _close(poll_fd[index].fd);
+ if ( (poll_fd[_index].handle != INVALID_HANDLE_VALUE) && (poll_fd[_index].handle != 0)
+ && (GetFileType(poll_fd[_index].handle) == FILE_TYPE_UNKNOWN) ) {
+ _close(poll_fd[_index].fd);
}
// close the duplicate handle (if we have an actual duplicate)
if (!CancelIoEx_Available) {
- if (_poll_fd[index].original_handle != INVALID_HANDLE_VALUE) {
- CloseHandle(poll_fd[index].handle);
+ if (_poll_fd[_index].original_handle != INVALID_HANDLE_VALUE) {
+ CloseHandle(poll_fd[_index].handle);
}
- _poll_fd[index].original_handle = INVALID_HANDLE_VALUE;
- _poll_fd[index].thread_id = 0;
+ _poll_fd[_index].original_handle = INVALID_HANDLE_VALUE;
+ _poll_fd[_index].thread_id = 0;
}
- free_overlapped(poll_fd[index].overlapped);
- poll_fd[index] = INVALID_WINFD;
+ free_overlapped(poll_fd[_index].overlapped);
+ poll_fd[_index] = INVALID_WINFD;
}
/*
@@ -485,16 +485,16 @@ void _free_index(int index)
*/
void usbi_free_fd(int fd)
{
- int index;
+ int _index;
CHECK_INIT_POLLING;
- index = _fd_to_index_and_lock(fd);
- if (index < 0) {
+ _index = _fd_to_index_and_lock(fd);
+ if (_index < 0) {
return;
}
- _free_index(index);
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ _free_index(_index);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
/*
@@ -586,7 +586,7 @@ struct winfd overlapped_to_winfd(OVERLAPPED* overlapped)
int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
{
unsigned i;
- int index, object_index, triggered;
+ int _index, object_index, triggered;
HANDLE *handles_to_wait_on;
int *handle_to_index;
DWORD nb_handles_to_wait_on = 0;
@@ -630,15 +630,15 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
goto poll_exit;
}
- index = _fd_to_index_and_lock(fds[i].fd);
+ _index = _fd_to_index_and_lock(fds[i].fd);
poll_dbg("fd[%d]=%d: (overlapped=%p) got events %04X", i, poll_fd[index].fd, poll_fd[index].overlapped, fds[i].events);
- if ( (index < 0) || (poll_fd[index].handle == INVALID_HANDLE_VALUE)
- || (poll_fd[index].handle == 0) || (poll_fd[index].overlapped == NULL)) {
+ if ( (_index < 0) || (poll_fd[_index].handle == INVALID_HANDLE_VALUE)
+ || (poll_fd[_index].handle == 0) || (poll_fd[_index].overlapped == NULL)) {
fds[i].revents |= POLLNVAL | POLLERR;
errno = EBADF;
- if (index >= 0) {
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ if (_index >= 0) {
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
usbi_warn(NULL, "invalid fd");
triggered = -1;
@@ -646,33 +646,33 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
}
// IN or OUT must match our fd direction
- if ((fds[i].events & POLLIN) && (poll_fd[index].rw != RW_READ)) {
+ if ((fds[i].events & POLLIN) && (poll_fd[_index].rw != RW_READ)) {
fds[i].revents |= POLLNVAL | POLLERR;
errno = EBADF;
usbi_warn(NULL, "attempted POLLIN on fd without READ access");
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
triggered = -1;
goto poll_exit;
}
- if ((fds[i].events & POLLOUT) && (poll_fd[index].rw != RW_WRITE)) {
+ if ((fds[i].events & POLLOUT) && (poll_fd[_index].rw != RW_WRITE)) {
fds[i].revents |= POLLNVAL | POLLERR;
errno = EBADF;
usbi_warn(NULL, "attempted POLLOUT on fd without WRITE access");
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
triggered = -1;
goto poll_exit;
}
// The following macro only works if overlapped I/O was reported pending
- if ( (HasOverlappedIoCompleted(poll_fd[index].overlapped))
- || (HasOverlappedIoCompletedSync(poll_fd[index].overlapped)) ) {
+ if ( (HasOverlappedIoCompleted(poll_fd[_index].overlapped))
+ || (HasOverlappedIoCompletedSync(poll_fd[_index].overlapped)) ) {
poll_dbg(" completed");
// checks above should ensure this works:
fds[i].revents = fds[i].events;
triggered++;
} else {
- handles_to_wait_on[nb_handles_to_wait_on] = poll_fd[index].overlapped->hEvent;
+ handles_to_wait_on[nb_handles_to_wait_on] = poll_fd[_index].overlapped->hEvent;
handle_to_index[nb_handles_to_wait_on] = i;
#if defined(DYNAMIC_FDS)
// If this fd from the poll set is also part of the new_fd event handle table, remove it
@@ -687,7 +687,7 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
#endif
nb_handles_to_wait_on++;
}
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
#if defined(DYNAMIC_FDS)
// At this stage, new_fd[] should only contain events from fds that
@@ -738,11 +738,11 @@ int usbi_poll(struct pollfd *fds, unsigned int nfds, int timeout)
#endif
poll_dbg(" completed after wait");
i = handle_to_index[object_index];
- index = _fd_to_index_and_lock(fds[i].fd);
+ _index = _fd_to_index_and_lock(fds[i].fd);
fds[i].revents = fds[i].events;
triggered++;
- if (index >= 0) {
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ if (_index >= 0) {
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
} else if (ret == WAIT_TIMEOUT) {
poll_dbg(" timed out");
@@ -773,28 +773,28 @@ poll_exit:
*/
int usbi_close(int fd)
{
- int index;
+ int _index;
int r = -1;
CHECK_INIT_POLLING;
- index = _fd_to_index_and_lock(fd);
+ _index = _fd_to_index_and_lock(fd);
- if (index < 0) {
+ if (_index < 0) {
errno = EBADF;
} else {
- if (poll_fd[index].overlapped != NULL) {
+ if (poll_fd[_index].overlapped != NULL) {
// Must be a different event for each end of the pipe
- CloseHandle(poll_fd[index].overlapped->hEvent);
- free(poll_fd[index].overlapped);
+ CloseHandle(poll_fd[_index].overlapped->hEvent);
+ free(poll_fd[_index].overlapped);
}
- if (CloseHandle(poll_fd[index].handle) == 0) {
+ if (CloseHandle(poll_fd[_index].handle) == 0) {
errno = EIO;
} else {
r = 0;
}
- poll_fd[index] = INVALID_WINFD;
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ poll_fd[_index] = INVALID_WINFD;
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
return r;
}
@@ -804,7 +804,7 @@ int usbi_close(int fd)
*/
ssize_t usbi_write(int fd, const void *buf, size_t count)
{
- int index;
+ int _index;
CHECK_INIT_POLLING;
@@ -813,24 +813,24 @@ ssize_t usbi_write(int fd, const void *buf, size_t count)
return -1;
}
- index = _fd_to_index_and_lock(fd);
+ _index = _fd_to_index_and_lock(fd);
- if ( (index < 0) || (poll_fd[index].overlapped == NULL) ) {
+ if ( (_index < 0) || (poll_fd[_index].overlapped == NULL) ) {
errno = EBADF;
- if (index >= 0) {
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ if (_index >= 0) {
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
}
return -1;
}
poll_dbg("set pipe event (fd = %d, thread = %08X)", index, GetCurrentThreadId());
- SetEvent(poll_fd[index].overlapped->hEvent);
- poll_fd[index].overlapped->Internal = STATUS_WAIT_0;
+ SetEvent(poll_fd[_index].overlapped->hEvent);
+ poll_fd[_index].overlapped->Internal = STATUS_WAIT_0;
// If two threads write on the pipe at the same time, we need to
// process two separate reads => use the overlapped as a counter
- poll_fd[index].overlapped->InternalHigh++;
+ poll_fd[_index].overlapped->InternalHigh++;
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
return sizeof(unsigned char);
}
@@ -839,7 +839,7 @@ ssize_t usbi_write(int fd, const void *buf, size_t count)
*/
ssize_t usbi_read(int fd, void *buf, size_t count)
{
- int index;
+ int _index;
ssize_t r = -1;
CHECK_INIT_POLLING;
@@ -849,30 +849,30 @@ ssize_t usbi_read(int fd, void *buf, size_t count)
return -1;
}
- index = _fd_to_index_and_lock(fd);
+ _index = _fd_to_index_and_lock(fd);
- if (index < 0) {
+ if (_index < 0) {
errno = EBADF;
return -1;
}
- if (WaitForSingleObject(poll_fd[index].overlapped->hEvent, INFINITE) != WAIT_OBJECT_0) {
+ if (WaitForSingleObject(poll_fd[_index].overlapped->hEvent, INFINITE) != WAIT_OBJECT_0) {
usbi_warn(NULL, "waiting for event failed: %d", (int)GetLastError());
errno = EIO;
goto out;
}
- poll_dbg("clr pipe event (fd = %d, thread = %08X)", index, GetCurrentThreadId());
- poll_fd[index].overlapped->InternalHigh--;
+ poll_dbg("clr pipe event (fd = %d, thread = %08X)", _index, GetCurrentThreadId());
+ poll_fd[_index].overlapped->InternalHigh--;
// Don't reset unless we don't have any more events to process
- if (poll_fd[index].overlapped->InternalHigh <= 0) {
- ResetEvent(poll_fd[index].overlapped->hEvent);
- poll_fd[index].overlapped->Internal = STATUS_PENDING;
+ if (poll_fd[_index].overlapped->InternalHigh <= 0) {
+ ResetEvent(poll_fd[_index].overlapped->hEvent);
+ poll_fd[_index].overlapped->Internal = STATUS_PENDING;
}
r = sizeof(unsigned char);
out:
- LeaveCriticalSection(&_poll_fd[index].mutex);
+ LeaveCriticalSection(&_poll_fd[_index].mutex);
return r;
}
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index d3709e4..364e2a5 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -309,13 +309,13 @@ static int Cfgmgr32_init(void)
* incremented index starting at zero) until all interfaces have been returned.
*/
SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ctx,
- HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, GUID guid, unsigned index)
+ HDEVINFO *dev_info, SP_DEVINFO_DATA *dev_info_data, GUID guid, unsigned _index)
{
SP_DEVICE_INTERFACE_DATA dev_interface_data;
SP_DEVICE_INTERFACE_DETAIL_DATA *dev_interface_details = NULL;
DWORD size;
- if (index <= 0) {
+ if (_index <= 0) {
*dev_info = SetupDiGetClassDevs(&guid, NULL, NULL, DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
}
if (*dev_info == INVALID_HANDLE_VALUE) {
@@ -324,10 +324,10 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct
if (dev_info_data != NULL) {
dev_info_data->cbSize = sizeof(SP_DEVINFO_DATA);
- if (!SetupDiEnumDeviceInfo(*dev_info, index, dev_info_data)) {
+ if (!SetupDiEnumDeviceInfo(*dev_info, _index, dev_info_data)) {
if (GetLastError() != ERROR_NO_MORE_ITEMS) {
usbi_err(ctx, "Could not obtain device info data for index %u: %s",
- index, windows_error_str(0));
+ _index, windows_error_str(0));
}
SetupDiDestroyDeviceInfoList(*dev_info);
*dev_info = INVALID_HANDLE_VALUE;
@@ -336,10 +336,10 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct
}
dev_interface_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
- if (!SetupDiEnumDeviceInterfaces(*dev_info, NULL, &guid, index, &dev_interface_data)) {
+ if (!SetupDiEnumDeviceInterfaces(*dev_info, NULL, &guid, _index, &dev_interface_data)) {
if (GetLastError() != ERROR_NO_MORE_ITEMS) {
usbi_err(ctx, "Could not obtain interface data for index %u: %s",
- index, windows_error_str(0));
+ _index, windows_error_str(0));
}
SetupDiDestroyDeviceInfoList(*dev_info);
*dev_info = INVALID_HANDLE_VALUE;
@@ -351,7 +351,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct
// The dummy call should fail with ERROR_INSUFFICIENT_BUFFER
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
usbi_err(ctx, "could not access interface data (dummy) for index %u: %s",
- index, windows_error_str(0));
+ _index, windows_error_str(0));
goto err_exit;
}
}
@@ -361,7 +361,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct
}
if ((dev_interface_details = malloc(size)) == NULL) {
- usbi_err(ctx, "could not allocate interface data for index %u.", index);
+ usbi_err(ctx, "could not allocate interface data for index %u.", _index);
goto err_exit;
}
@@ -369,7 +369,7 @@ SP_DEVICE_INTERFACE_DETAIL_DATA *get_interface_details(struct libusb_context *ct
if (!SetupDiGetDeviceInterfaceDetail(*dev_info, &dev_interface_data,
dev_interface_details, size, &size, NULL)) {
usbi_err(ctx, "could not access interface data (actual) for index %u: %s",
- index, windows_error_str(0));
+ _index, windows_error_str(0));
}
return dev_interface_details;
@@ -3086,7 +3086,7 @@ static int _hid_get_config_descriptor(struct hid_device_priv* dev, void *data, s
return LIBUSB_COMPLETED;
}
-static int _hid_get_string_descriptor(struct hid_device_priv* dev, int index,
+static int _hid_get_string_descriptor(struct hid_device_priv* dev, int _index,
void *data, size_t *size)
{
void *tmp = NULL;
@@ -3103,12 +3103,12 @@ static int _hid_get_string_descriptor(struct hid_device_priv* dev, int index,
return LIBUSB_ERROR_OVERFLOW;
}
- if (index == 0) {
+ if (_index == 0) {
tmp = string_langid;
tmp_size = sizeof(string_langid)+2;
} else {
for (i=0; i<3; i++) {
- if (index == (dev->string_index[i])) {
+ if (_index == (dev->string_index[i])) {
tmp = dev->string[i];
tmp_size = (_hid_wcslen(dev->string[i])+1) * sizeof(WCHAR);
break;
@@ -3222,7 +3222,7 @@ static int _hid_get_report_descriptor(struct hid_device_priv* dev, void *data, s
}
static int _hid_get_descriptor(struct hid_device_priv* dev, HANDLE hid_handle, int recipient,
- int type, int index, void *data, size_t *size)
+ int type, int _index, void *data, size_t *size)
{
switch(type) {
case LIBUSB_DT_DEVICE:
@@ -3230,20 +3230,20 @@ static int _hid_get_descriptor(struct hid_device_priv* dev, HANDLE hid_handle, i
return _hid_get_device_descriptor(dev, data, size);
case LIBUSB_DT_CONFIG:
usbi_dbg("LIBUSB_DT_CONFIG");
- if (!index)
+ if (!_index)
return _hid_get_config_descriptor(dev, data, size);
return LIBUSB_ERROR_INVALID_PARAM;
case LIBUSB_DT_STRING:
usbi_dbg("LIBUSB_DT_STRING");
- return _hid_get_string_descriptor(dev, index, data, size);
+ return _hid_get_string_descriptor(dev, _index, data, size);
case LIBUSB_DT_HID:
usbi_dbg("LIBUSB_DT_HID");
- if (!index)
+ if (!_index)
return _hid_get_hid_descriptor(dev, data, size);
return LIBUSB_ERROR_INVALID_PARAM;
case LIBUSB_DT_REPORT:
usbi_dbg("LIBUSB_DT_REPORT");
- if (!index)
+ if (!_index)
return _hid_get_report_descriptor(dev, data, size);
return LIBUSB_ERROR_INVALID_PARAM;
case LIBUSB_DT_PHYSICAL:
@@ -3415,7 +3415,7 @@ static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int i
}
static int _hid_class_request(struct hid_device_priv* dev, HANDLE hid_handle, int request_type,
- int request, int value, int index, void *data, struct windows_transfer_priv *tp,
+ int request, int value, int _index, void *data, struct windows_transfer_priv *tp,
size_t *size, OVERLAPPED* overlapped)
{
int report_type = (value >> 8) & 0xFF;