summaryrefslogtreecommitdiff
path: root/gusb/gusb-device.c
diff options
context:
space:
mode:
Diffstat (limited to 'gusb/gusb-device.c')
-rw-r--r--gusb/gusb-device.c41
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 {