Fixed building HIDAPI libusb support on Windows
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
diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c
index c740be5..24ae052 100644
--- a/src/hidapi/libusb/hid.c
+++ b/src/hidapi/libusb/hid.c
@@ -28,8 +28,16 @@
*/
#include "../../SDL_internal.h"
-#include "SDL_thread.h"
+#include "../../thread/SDL_systhread.h"
#include "SDL_mutex.h"
+#include "SDL_thread.h"
+
+#define realloc SDL_realloc
+#define snprintf SDL_snprintf
+#define strdup SDL_strdup
+#define strncpy SDL_strlcpy
+#define tolower SDL_tolower
+#define wcsncpy SDL_wcslcpy
#ifndef HAVE_WCSDUP
#ifdef HAVE__WCSDUP
@@ -51,7 +59,10 @@ static wchar_t *_dupwcs(const wchar_t *src)
#endif /* HAVE_WCSDUP */
#include <libusb.h>
+#ifndef _WIN32
+#define HAVE_SETLOCALE
#include <locale.h> /* setlocale */
+#endif
#include "../hidapi/hidapi.h"
@@ -599,16 +610,18 @@ static char *make_path(libusb_device *dev, int interface_number)
int HID_API_EXPORT hid_init(void)
{
if (!usb_context) {
- const char *locale;
-
/* Init Libusb */
if (libusb_init(&usb_context))
return -1;
+#ifdef HAVE_SETLOCALE
/* Set the locale if it's not set. */
- locale = setlocale(LC_CTYPE, NULL);
- if (!locale)
- setlocale(LC_CTYPE, "");
+ {
+ const char *locale = setlocale(LC_CTYPE, NULL);
+ if (!locale)
+ setlocale(LC_CTYPE, "");
+ }
+#endif
}
return 0;
@@ -1288,7 +1301,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
calculate_device_quirks(dev, desc.idVendor, desc.idProduct);
- dev->thread = SDL_CreateThread(read_thread, NULL, dev);
+ dev->thread = SDL_CreateThreadInternal(read_thread, "libusb", 0, dev);
/* Wait here for the read thread to be initialized. */
SDL_WaitThreadBarrier(&dev->barrier);
@@ -1767,13 +1780,15 @@ static struct lang_map_entry lang_map[] = {
uint16_t get_usb_code_for_current_locale(void)
{
- char *locale;
+ char *locale = NULL;
char search_string[64];
char *ptr;
struct lang_map_entry *lang;
/* Get the current locale. */
+#ifdef HAVE_SETLOCALE
locale = setlocale(0, NULL);
+#endif
if (!locale)
return 0x0;