MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / get_usb_string

Function get_usb_string

dependencies/hidapi/hidapi.c:310–347  ·  view source on GitHub ↗

This function returns a newly allocated wide string containing the USB device string numbered by the index. The returned string must be freed by using free(). */

Source from the content-addressed store, hash-verified

308 device string numbered by the index. The returned string must be freed
309 by using free(). */
310static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
311{
312 char buf[512];
313 int len;
314 wchar_t *str = NULL;
315
316 /* Determine which language to use. */
317 uint16_t lang;
318 lang = get_usb_code_for_current_locale();
319 if (!is_language_supported(dev, lang))
320 lang = get_first_language(dev);
321
322 /* Get the string from libusb. */
323 len = libusb_get_string_descriptor(dev,
324 idx,
325 lang,
326 (unsigned char*)buf,
327 sizeof(buf));
328 if (len < 0)
329 return NULL;
330
331 /* Bionic does not have iconv support nor wcsdup() function, so it
332 has to be done manually. The following code will only work for
333 code points that can be represented as a single UTF-16 character,
334 and will incorrectly convert any code points which require more
335 than one UTF-16 character.
336
337 Skip over the first character (2-bytes). */
338 len -= 2;
339 str = malloc((len / 2 + 1) * sizeof(wchar_t));
340 int i;
341 for (i = 0; i < len / 2; i++) {
342 str[i] = buf[i * 2 + 2] | (buf[i * 2 + 3] << 8);
343 }
344 str[len / 2] = 0x00000000;
345
346 return str;
347}
348
349static char *make_path(libusb_device *dev, int interface_number)
350{

Callers 2

hid_enumerateFunction · 0.85
hid_get_indexed_stringFunction · 0.85

Calls 4

is_language_supportedFunction · 0.85
get_first_languageFunction · 0.85

Tested by

no test coverage detected