From c6deb2f345edc90ea975bf2e66e3eb589a878e03 Mon Sep 17 00:00:00 2001 From: Tormod Volden Date: Wed, 2 Feb 2022 18:15:59 +0100 Subject: darwin: Avoid cast warnings in time calculation Also use the USEC_PER_SEC macro for readability. References #1035 Signed-off-by: Tormod Volden --- libusb/os/darwin_usb.c | 7 ++++--- libusb/version_nano.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c index 4fac3fd..af3c4e9 100644 --- a/libusb/os/darwin_usb.c +++ b/libusb/os/darwin_usb.c @@ -43,7 +43,7 @@ /* Default timeout to 10s for reenumerate. This is needed because USBDeviceReEnumerate * does not return error status on macOS. */ -#define DARWIN_REENUMERATE_TIMEOUT_US 10000000 +#define DARWIN_REENUMERATE_TIMEOUT_US (10 * USEC_PER_SEC) #include #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 && MAC_OS_X_VERSION_MIN_REQUIRED < 101200 @@ -1809,9 +1809,10 @@ static int darwin_reenumerate_device (struct libusb_device_handle *dev_handle, b struct timespec now; usbi_get_monotonic_time(&now); - UInt32 elapsed = (now.tv_sec - start.tv_sec) * 1000000 + (now.tv_nsec - start.tv_nsec) / 1000; + unsigned long elapsed_us = (now.tv_sec - start.tv_sec) * USEC_PER_SEC + + (now.tv_nsec - start.tv_nsec) / 1000; - if (elapsed >= DARWIN_REENUMERATE_TIMEOUT_US) { + if (elapsed_us >= DARWIN_REENUMERATE_TIMEOUT_US) { usbi_err (ctx, "darwin/reenumerate_device: timeout waiting for reenumerate"); dpriv->in_reenumerate = false; return LIBUSB_ERROR_TIMEOUT; diff --git a/libusb/version_nano.h b/libusb/version_nano.h index e7daf21..65127d8 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11702 +#define LIBUSB_NANO 11703 -- cgit v1.2.1