Skip to content

Commit c76f25e

Browse files
committed
Use the new libusb_init_context function
The old libusb_init function is deprecated and may be removed in the future. Detect the API change through the LIBUSB_API_VERSION macro and fallback to the old function for compatibility with older libusb versions.
1 parent 6ccb0d0 commit c76f25e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/usb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ dc_usb_session_new (dc_usb_session_t **out, dc_context_t *context)
190190

191191
session->refcount = 1;
192192

193+
#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x0100010A)
194+
int rc = libusb_init_context (&session->handle, NULL, 0);
195+
#else
193196
int rc = libusb_init (&session->handle);
197+
#endif
194198
if (rc != LIBUSB_SUCCESS) {
195199
ERROR (context, "Failed to initialize usb support (%s).",
196200
libusb_error_name (rc));

src/usbhid.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,11 @@ dc_usbhid_session_new (dc_usbhid_session_t **out, dc_context_t *context)
240240
session->refcount = 1;
241241

242242
#if defined(USE_LIBUSB)
243+
#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x0100010A)
244+
int rc = libusb_init_context (&session->handle, NULL, 0);
245+
#else
243246
int rc = libusb_init (&session->handle);
247+
#endif
244248
if (rc != LIBUSB_SUCCESS) {
245249
ERROR (context, "Failed to initialize usb support (%s).",
246250
libusb_error_name (rc));

0 commit comments

Comments
 (0)