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(). */
| 308 | device string numbered by the index. The returned string must be freed |
| 309 | by using free(). */ |
| 310 | static 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 | |
| 349 | static char *make_path(libusb_device *dev, int interface_number) |
| 350 | { |
no test coverage detected