diff --git a/linux/hid-libusb.c b/linux/hid-libusb.c index 9ec3cbc..844523f 100644 --- a/linux/hid-libusb.c +++ b/linux/hid-libusb.c @@ -385,8 +385,16 @@ 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; + + /* Set the locale if it's not set. */ + locale = setlocale(LC_CTYPE, NULL); + if (!locale) + setlocale(LC_CTYPE, ""); } return 0; @@ -413,8 +421,6 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, struct hid_device_info *root = NULL; // return object struct hid_device_info *cur_dev = NULL; - setlocale(LC_ALL,""); - hid_init(); num_devs = libusb_get_device_list(usb_context, &devs); diff --git a/linux/hid.c b/linux/hid.c index 5a0d41b..7f34f00 100644 --- a/linux/hid.c +++ b/linux/hid.c @@ -164,8 +164,6 @@ static int get_device_string(hid_device *dev, const char *key, wchar_t *string, struct stat s; int ret = -1; - setlocale(LC_ALL,""); - /* Create the udev object */ udev = udev_new(); if (!udev) { @@ -205,7 +203,13 @@ end: int HID_API_EXPORT hid_init(void) { - /* Nothing to do for this in the Linux/hidraw implementation. */ + const char *locale; + + /* Set the locale if it's not set. */ + locale = setlocale(LC_CTYPE, NULL); + if (!locale) + setlocale(LC_CTYPE, ""); + return 0; } @@ -223,8 +227,8 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, struct hid_device_info *root = NULL; // return object struct hid_device_info *cur_dev = NULL; - - setlocale(LC_ALL,""); + + hid_init(); /* Create the udev object */ udev = udev_new(); @@ -404,6 +408,8 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) { hid_device *dev = NULL; + hid_init(); + dev = new_hid_device(); if (kernel_version == 0) {