Fix build with newer version of libusb

reverse-scroll
nirenjan 2021-09-14 09:28:00 -07:00
parent fa1d54f9da
commit 3a81acf828
1 changed files with 19 additions and 2 deletions

View File

@ -289,10 +289,27 @@ int libusb_has_capability(uint32_t capability)
return capability == LIBUSB_CAP_HAS_HOTPLUG; return capability == LIBUSB_CAP_HAS_HOTPLUG;
} }
/*
* libusb 1.0.24 (and newer) changed the signature of
* libusb_hotplug_register_callback. Older versions used the enum, but this
* was changed to int to address libusb/libusb#714.
*
* This causes issues when building on older systems, since it complains
* about conflicting types. In order to resolve this, we need to dynamically
* determine the parameters based on the libusb version.
*/
#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000108)
#define LIBUSB_HOTPLUG_EVENT int
#define LIBUSB_HOTPLUG_FLAG int
#else
#define LIBUSB_HOTPLUG_EVENT libusb_hotplug_event
#define LIBUSB_HOTPLUG_FLAG libusb_hotplug_flag
#endif
/* Dummy function to simulate registering callbacks */ /* Dummy function to simulate registering callbacks */
int libusb_hotplug_register_callback(libusb_context *ctx, int libusb_hotplug_register_callback(libusb_context *ctx,
libusb_hotplug_event events, LIBUSB_HOTPLUG_EVENT events,
libusb_hotplug_flag flags, LIBUSB_HOTPLUG_FLAG flags,
int vendor_id, int product_id, int dev_class, int vendor_id, int product_id, int dev_class,
libusb_hotplug_callback_fn cb_fn, void *user_data, libusb_hotplug_callback_fn cb_fn, void *user_data,
libusb_hotplug_callback_handle *callback_handle) libusb_hotplug_callback_handle *callback_handle)