From 404ec13fbb3df4c8fc4d983e4386d48053e9cd58 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 24 Oct 2025 10:29:39 -0700
Subject: [PATCH] Fixed building with libusb on FreeBSD
---
src/hidapi/SDL_hidapi_libusb.h | 19 +++++++++++++++++--
src/hidapi/libusb/hid.c | 2 +-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/hidapi/SDL_hidapi_libusb.h b/src/hidapi/SDL_hidapi_libusb.h
index ed8b4a35d7022..ec0e5b265d661 100644
--- a/src/hidapi/SDL_hidapi_libusb.h
+++ b/src/hidapi/SDL_hidapi_libusb.h
@@ -82,7 +82,6 @@
#define wcsncpy SDL_wcslcpy
-#ifndef SDL_PLATFORM_FREEBSD
/* this is awkwardly inlined, so we need to re-implement it here
* so we can override the libusb_control_transfer call */
static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
@@ -93,7 +92,23 @@ static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
}
#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
-#endif /* SDL_PLATFORM_FREEBSD */
+
+/* this is inlined, except on FreeBSD, so we need to re-implement it here */
+static void SDL_libusb_fill_interrupt_transfer(
+ struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
+ unsigned char endpoint, unsigned char *buffer, int length,
+ libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
+{
+ transfer->dev_handle = dev_handle;
+ transfer->endpoint = endpoint;
+ transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
+ transfer->timeout = timeout;
+ transfer->buffer = buffer;
+ transfer->length = length;
+ transfer->user_data = user_data;
+ transfer->callback = callback;
+}
+#define libusb_fill_interrupt_transfer SDL_libusb_fill_interrupt_transfer
#define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h"
#ifndef LIBUSB_API_VERSION
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index 71731a45ef6d8..16bec68f188b3 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -288,7 +288,7 @@ static int get_usage(uint8_t *report_descriptor, size_t size,
return -1; /* failure */
}
-#if defined(__FreeBSD__) && __FreeBSD__ < 10
+#if defined(__FreeBSD__) && __FreeBSD__ < 10 && !defined(libusb_get_string_descriptor)
/* The libusb version included in FreeBSD < 10 doesn't have this function. In
mainline libusb, it's inlined in libusb.h. This function will bear a striking
resemblance to that one, because there's about one way to code it.