*/
#include "libusbi.h"
+#include "windows_common.h"
#include <errno.h>
#include <intrin.h>
for (n = 0; n < fd_table_size; n += BITMAP_BITS_PER_WORD) {
unsigned int idx = n / BITMAP_BITS_PER_WORD;
- unsigned long mask, pos = 0UL;
+ ULONG mask, pos = 0U;
mask = ~fd_table_bitmap[idx];
- if (mask == 0UL)
+ if (mask == 0U)
continue;
assert(_BitScanForward(&pos, mask));
- fd_table_bitmap[idx] |= 1UL << pos;
+ fd_table_bitmap[idx] |= 1U << pos;
n += pos;
break;
}
{
assert(fd_table[pos] != NULL);
fd_table[pos] = NULL;
- fd_table_bitmap[pos / BITMAP_BITS_PER_WORD] &= ~(1UL << (pos % BITMAP_BITS_PER_WORD));
+ fd_table_bitmap[pos / BITMAP_BITS_PER_WORD] &= ~(1U << (pos % BITMAP_BITS_PER_WORD));
fd_count--;
if (fd_count == 0) {
free(fd_table);
for (n = 0; n < num_threads; n++) {
if (thread_data[n].thread != NULL) {
if (WaitForSingleObject(thread_data[n].thread, INFINITE) != WAIT_OBJECT_0)
- usbi_err(NULL, "WaitForSingleObject() failed: %lu", GetLastError());
+ usbi_err(NULL, "WaitForSingleObject() failed: %lu", ULONG_CAST(GetLastError()));
CloseHandle(thread_data[n].thread);
}
if (thread_data[n].error) {
- usbi_err(NULL, "wait thread %d had error %lu\n", n, thread_data[n].error);
+ usbi_err(NULL, "wait thread %d had error %lu\n", n, ULONG_CAST(thread_data[n].error));
error = thread_data[n].error;
status = WAIT_FAILED;
}
assert(timeout > 0);
timeout = 0;
} else if (ret == WAIT_FAILED) {
- usbi_err(NULL, "WaitForMultipleObjects failed: %lu", GetLastError());
+ usbi_err(NULL, "WaitForMultipleObjects failed: %lu", ULONG_CAST(GetLastError()));
errno = EIO;
nready = -1;
}
if (error_code == 0)
error_code = GetLastError();
- len = sprintf(err_string, "[%lu] ", error_code);
+ len = sprintf(err_string, "[%lu] ", ULONG_CAST(error_code));
// Translate codes returned by SetupAPI. The ones we are dealing with are either
// in 0x0000xxxx or 0xE000xxxx and can be distinguished from standard error codes.
if (format_error)
snprintf(err_string, sizeof(err_string),
"Windows error code %lu (FormatMessage error code %lu)",
- error_code, format_error);
+ ULONG_CAST(error_code), ULONG_CAST(format_error));
else
- snprintf(err_string, sizeof(err_string), "Unknown error code %lu", error_code);
+ snprintf(err_string, sizeof(err_string), "Unknown error code %lu",
+ ULONG_CAST(error_code));
} else {
// Remove CRLF from end of message, if present
size_t pos = len + size - 2;
{
int status, istatus;
- usbi_dbg("handling I/O completion with errcode %lu, size %lu", io_result, io_size);
+ usbi_dbg("handling I/O completion with errcode %lu, size %lu",
+ ULONG_CAST(io_result), ULONG_CAST(io_size));
switch (io_result) {
case NO_ERROR:
status = LIBUSB_TRANSFER_NO_DEVICE;
break;
default:
- usbi_err(ITRANSFER_CTX(itransfer), "detected I/O error %lu: %s", io_result, windows_error_str(io_result));
+ usbi_err(ITRANSFER_CTX(itransfer), "detected I/O error %lu: %s",
+ ULONG_CAST(io_result), windows_error_str(io_result));
status = LIBUSB_TRANSFER_ERROR;
break;
}
if (!pSetupDiEnumDeviceInfo(dev_info, *_index, dev_info_data)) {
if (GetLastError() != ERROR_NO_MORE_ITEMS) {
usbi_err(ctx, "Could not obtain device info data for %s index %lu: %s",
- guid_to_string(guid), *_index, windows_error_str(0));
+ guid_to_string(guid), ULONG_CAST(*_index), windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
if (GetLastError() != ERROR_NO_MORE_ITEMS) {
usbi_err(ctx, "Could not obtain interface data for %s devInst %lX: %s",
- guid_to_string(guid), dev_info_data->DevInst, windows_error_str(0));
+ guid_to_string(guid), ULONG_CAST(dev_info_data->DevInst), windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
// The dummy call should fail with ERROR_INSUFFICIENT_BUFFER
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
usbi_err(ctx, "could not access interface data (dummy) for %s devInst %lX: %s",
- guid_to_string(guid), dev_info_data->DevInst, windows_error_str(0));
+ guid_to_string(guid), ULONG_CAST(dev_info_data->DevInst), windows_error_str(0));
return LIBUSB_ERROR_OTHER;
}
} else {
dev_interface_details = malloc(size);
if (dev_interface_details == NULL) {
usbi_err(ctx, "could not allocate interface data for %s devInst %lX",
- guid_to_string(guid), dev_info_data->DevInst);
+ guid_to_string(guid), ULONG_CAST(dev_info_data->DevInst));
return LIBUSB_ERROR_NO_MEM;
}
if (!pSetupDiGetDeviceInterfaceDetailA(dev_info, &dev_interface_data,
dev_interface_details, size, NULL, NULL)) {
usbi_err(ctx, "could not access interface data (actual) for %s devInst %lX: %s",
- guid_to_string(guid), dev_info_data->DevInst, windows_error_str(0));
+ guid_to_string(guid), ULONG_CAST(dev_info_data->DevInst), windows_error_str(0));
free(dev_interface_details);
return LIBUSB_ERROR_OTHER;
}
if (*dev_interface_path == NULL) {
usbi_err(ctx, "could not allocate interface path for %s devInst %lX",
- guid_to_string(guid), dev_info_data->DevInst);
+ guid_to_string(guid), ULONG_CAST(dev_info_data->DevInst));
return LIBUSB_ERROR_NO_MEM;
}
// Read the Device ID path
if (!pSetupDiGetDeviceInstanceIdA(*dev_info, &dev_info_data, dev_id, sizeof(dev_id), NULL)) {
usbi_warn(ctx, "could not read the device instance ID for devInst %lX, skipping",
- dev_info_data.DevInst);
+ ULONG_CAST(dev_info_data.DevInst));
continue;
}
usbi_warn(ctx, "could not detect installation state of driver for '%s': %s",
dev_id, windows_error_str(0));
} else if (install_state != 0) {
- usbi_warn(ctx, "driver for device '%s' is reporting an issue (code: %u) - skipping",
- dev_id, (unsigned int)install_state);
+ usbi_warn(ctx, "driver for device '%s' is reporting an issue (code: %lu) - skipping",
+ dev_id, ULONG_CAST(install_state));
continue;
}
get_api_type(dev_info, &dev_info_data, &api, &sub_api);
case USBD_STATUS_DEVICE_GONE:
return LIBUSB_TRANSFER_NO_DEVICE;
default:
- usbi_dbg("USBD_STATUS 0x%08lx translated to LIBUSB_TRANSFER_ERROR", status);
+ usbi_dbg("USBD_STATUS 0x%08lx translated to LIBUSB_TRANSFER_ERROR", ULONG_CAST(status));
return LIBUSB_TRANSFER_ERROR;
}
}
size[1] = capabilities.NumberOutputValueCaps;
size[2] = capabilities.NumberFeatureValueCaps;
for (j = HidP_Input; j <= HidP_Feature; j++) {
- usbi_dbg("%lu HID %s report value(s) found", size[j], type[j]);
+ usbi_dbg("%lu HID %s report value(s) found", ULONG_CAST(size[j]), type[j]);
priv->hid->uses_report_ids[j] = false;
if (size[j] > 0) {
value_caps = calloc(size[j], sizeof(HIDP_VALUE_CAPS));