diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-11-18 16:08:26 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-11-18 13:58:59 -0800 |
commit | 5121cb55714899857630ef368861fb9ea9fc6752 (patch) | |
tree | 664b02b3d29f3f2a13c69834029578eae99b5a5b /usbmisc.c | |
parent | 184c462c0e71fb606cd9f9c96eb403d3c9f7ccc2 (diff) | |
download | usbutils-5121cb55714899857630ef368861fb9ea9fc6752.tar.gz |
usbutils: convert to libusb-1.0
We need to eat our own dog food.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'usbmisc.c')
-rw-r--r-- | usbmisc.c | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -119,24 +119,32 @@ static char *get_absolute_path(const char *path, char *result, return result; } -struct usb_device *get_usb_device(const char *path) +libusb_device *get_usb_device(libusb_context *ctx, const char *path) { - struct usb_bus *bus; - struct usb_device *dev; + libusb_device **list; + libusb_device *dev; + ssize_t num_devs, i; char device_path[PATH_MAX + 1]; char absolute_path[PATH_MAX + 1]; readlink_recursive(path, device_path, sizeof(device_path)); get_absolute_path(device_path, absolute_path, sizeof(absolute_path)); - for (bus = usb_busses; bus; bus = bus->next) { - for (dev = bus->devices; dev; dev = dev->next) { - snprintf(device_path, sizeof(device_path), "%s/%s/%s", - devbususb, bus->dirname, dev->filename); - if (!strcmp(device_path, absolute_path)) - return dev; + dev = NULL; + num_devs = libusb_get_device_list(ctx, &list); + + for (i = 0; i < num_devs; ++i) { + uint8_t bnum = libusb_get_bus_number(list[i]); + uint8_t dnum = libusb_get_device_address(list[i]); + + snprintf(device_path, sizeof(device_path), "%s/%03u/%03u", + devbususb, bnum, dnum); + if (!strcmp(device_path, absolute_path)) { + dev = list[i]; + break; } } - return NULL; -} + libusb_free_device_list(list, 0); + return dev; +} |