diff options
author | Richard Hughes <richard@hughsie.com> | 2021-01-20 18:33:53 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2021-01-27 15:12:54 +0000 |
commit | 38d1f8b3af5e76b548b5701f39ac9dd8a74bde9e (patch) | |
tree | b23032bb274c9e424a980669f1967096eae75577 /gusb/gusb-device.c | |
parent | 87333b579758c87d87ad9929931b654437186d71 (diff) | |
download | gusb-38d1f8b3af5e76b548b5701f39ac9dd8a74bde9e.tar.gz |
Add g_usb_device_get_string_descriptor_bytes()
This is requried for the GD32VF103 device.
Diffstat (limited to 'gusb/gusb-device.c')
-rw-r--r-- | gusb/gusb-device.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index 248b6f3..4637cf3 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -889,6 +889,47 @@ g_usb_device_get_string_descriptor (GUsbDevice *device, return g_strdup ((const gchar *)buf); } +/** + * g_usb_device_get_string_descriptor_bytes: + * @desc_index: the index for the string descriptor to retrieve + * @langid: the language ID + * @error: a #GError, or %NULL + * + * Get a raw string descriptor from the device. The returned string should be freed + * with g_bytes_unref() when no longer needed. + * + * Return value: (transfer full): a possibly UTF-16 string, or NULL on error. + * + * Since: 0.3.6 + **/ +GBytes * +g_usb_device_get_string_descriptor_bytes (GUsbDevice *device, + guint8 desc_index, + guint16 langid, + GError **error) +{ + gint rc; + unsigned char buf[128]; + + g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + if (device->priv->handle == NULL) { + g_usb_device_not_open_error (device, error); + return NULL; + } + + rc = libusb_get_string_descriptor (device->priv->handle, + desc_index, langid, + buf, sizeof(buf)); + if (rc < 0) { + g_usb_device_libusb_error_to_gerror (device, rc, error); + return NULL; + } + + return g_bytes_new (buf, rc); +} + typedef gssize (GUsbDeviceTransferFinishFunc) (GUsbDevice *device, GAsyncResult *res, GError **error); typedef struct { |