hidapi: Allow disabling libusb support at runtime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index 3808ceb..fa8e56e 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -1037,54 +1037,60 @@ int SDL_hid_init(void)
#endif
#ifdef SDL_LIBUSB_DYNAMIC
- ++attempts;
- libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
- if (libusb_ctx.libhandle != NULL) {
- SDL_bool loaded = SDL_TRUE;
- #ifdef __OS2__
- #define LOAD_LIBUSB_SYMBOL(func) \
- if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle,"_libusb_" #func))) {loaded = SDL_FALSE;}
- #else
- #define LOAD_LIBUSB_SYMBOL(func) \
- if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
- #endif
- LOAD_LIBUSB_SYMBOL(init)
- LOAD_LIBUSB_SYMBOL(exit)
- LOAD_LIBUSB_SYMBOL(get_device_list)
- LOAD_LIBUSB_SYMBOL(free_device_list)
- LOAD_LIBUSB_SYMBOL(get_device_descriptor)
- LOAD_LIBUSB_SYMBOL(get_active_config_descriptor)
- LOAD_LIBUSB_SYMBOL(get_config_descriptor)
- LOAD_LIBUSB_SYMBOL(free_config_descriptor)
- LOAD_LIBUSB_SYMBOL(get_bus_number)
- LOAD_LIBUSB_SYMBOL(get_device_address)
- LOAD_LIBUSB_SYMBOL(open)
- LOAD_LIBUSB_SYMBOL(close)
- LOAD_LIBUSB_SYMBOL(claim_interface)
- LOAD_LIBUSB_SYMBOL(release_interface)
- LOAD_LIBUSB_SYMBOL(kernel_driver_active)
- LOAD_LIBUSB_SYMBOL(detach_kernel_driver)
- LOAD_LIBUSB_SYMBOL(attach_kernel_driver)
- LOAD_LIBUSB_SYMBOL(set_interface_alt_setting)
- LOAD_LIBUSB_SYMBOL(alloc_transfer)
- LOAD_LIBUSB_SYMBOL(submit_transfer)
- LOAD_LIBUSB_SYMBOL(cancel_transfer)
- LOAD_LIBUSB_SYMBOL(free_transfer)
- LOAD_LIBUSB_SYMBOL(control_transfer)
- LOAD_LIBUSB_SYMBOL(interrupt_transfer)
- LOAD_LIBUSB_SYMBOL(handle_events)
- LOAD_LIBUSB_SYMBOL(handle_events_completed)
- #undef LOAD_LIBUSB_SYMBOL
-
- if (!loaded) {
- SDL_UnloadObject(libusb_ctx.libhandle);
- libusb_ctx.libhandle = NULL;
- /* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
- } else if (LIBUSB_hid_init() < 0) {
- SDL_UnloadObject(libusb_ctx.libhandle);
- libusb_ctx.libhandle = NULL;
- } else {
- ++success;
+ if (SDL_getenv("SDL_HIDAPI_DISABLE_LIBUSB") != NULL) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "libusb disabled by SDL_HIDAPI_DISABLE_LIBUSB");
+ libusb_ctx.libhandle = NULL;
+ } else {
+ ++attempts;
+ libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
+ if (libusb_ctx.libhandle != NULL) {
+ SDL_bool loaded = SDL_TRUE;
+ #ifdef __OS2__
+ #define LOAD_LIBUSB_SYMBOL(func) \
+ if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle,"_libusb_" #func))) {loaded = SDL_FALSE;}
+ #else
+ #define LOAD_LIBUSB_SYMBOL(func) \
+ if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
+ #endif
+ LOAD_LIBUSB_SYMBOL(init)
+ LOAD_LIBUSB_SYMBOL(exit)
+ LOAD_LIBUSB_SYMBOL(get_device_list)
+ LOAD_LIBUSB_SYMBOL(free_device_list)
+ LOAD_LIBUSB_SYMBOL(get_device_descriptor)
+ LOAD_LIBUSB_SYMBOL(get_active_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(get_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(free_config_descriptor)
+ LOAD_LIBUSB_SYMBOL(get_bus_number)
+ LOAD_LIBUSB_SYMBOL(get_device_address)
+ LOAD_LIBUSB_SYMBOL(open)
+ LOAD_LIBUSB_SYMBOL(close)
+ LOAD_LIBUSB_SYMBOL(claim_interface)
+ LOAD_LIBUSB_SYMBOL(release_interface)
+ LOAD_LIBUSB_SYMBOL(kernel_driver_active)
+ LOAD_LIBUSB_SYMBOL(detach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(attach_kernel_driver)
+ LOAD_LIBUSB_SYMBOL(set_interface_alt_setting)
+ LOAD_LIBUSB_SYMBOL(alloc_transfer)
+ LOAD_LIBUSB_SYMBOL(submit_transfer)
+ LOAD_LIBUSB_SYMBOL(cancel_transfer)
+ LOAD_LIBUSB_SYMBOL(free_transfer)
+ LOAD_LIBUSB_SYMBOL(control_transfer)
+ LOAD_LIBUSB_SYMBOL(interrupt_transfer)
+ LOAD_LIBUSB_SYMBOL(handle_events)
+ LOAD_LIBUSB_SYMBOL(handle_events_completed)
+ #undef LOAD_LIBUSB_SYMBOL
+
+ if (!loaded) {
+ SDL_UnloadObject(libusb_ctx.libhandle);
+ libusb_ctx.libhandle = NULL;
+ /* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
+ } else if (LIBUSB_hid_init() < 0) {
+ SDL_UnloadObject(libusb_ctx.libhandle);
+ libusb_ctx.libhandle = NULL;
+ } else {
+ ++success;
+ }
}
}
#endif /* SDL_LIBUSB_DYNAMIC */