summaryrefslogtreecommitdiffstats
path: root/third_party/libusb/examples/lsusb.c
diff options
context:
space:
mode:
authorgdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-27 00:36:20 +0000
committergdk@chromium.org <gdk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-27 00:36:20 +0000
commit36ed39d3e18c4acdf062c10af072253581cbbd0c (patch)
tree8863f3daf6a5c5bea5ab82dbac15a590068738f6 /third_party/libusb/examples/lsusb.c
parent922ad1e2f969a6fce707caf1059134637272e890 (diff)
downloadchromium_src-36ed39d3e18c4acdf062c10af072253581cbbd0c.zip
chromium_src-36ed39d3e18c4acdf062c10af072253581cbbd0c.tar.gz
chromium_src-36ed39d3e18c4acdf062c10af072253581cbbd0c.tar.bz2
Import libusb 1.0.9-rc3 into third_party.
BUG=none TEST=none Review URL: http://codereview.chromium.org/9826025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/libusb/examples/lsusb.c')
-rw-r--r--third_party/libusb/examples/lsusb.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/third_party/libusb/examples/lsusb.c b/third_party/libusb/examples/lsusb.c
new file mode 100644
index 0000000..6ab8917
--- /dev/null
+++ b/third_party/libusb/examples/lsusb.c
@@ -0,0 +1,64 @@
+/*
+ * libusb example program to list devices on the bus
+ * Copyright (C) 2007 Daniel Drake <dsd@gentoo.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+
+#include <libusb.h>
+
+static void print_devs(libusb_device **devs)
+{
+ libusb_device *dev;
+ int i = 0;
+
+ while ((dev = devs[i++]) != NULL) {
+ struct libusb_device_descriptor desc;
+ int r = libusb_get_device_descriptor(dev, &desc);
+ if (r < 0) {
+ fprintf(stderr, "failed to get device descriptor");
+ return;
+ }
+
+ printf("%04x:%04x (bus %d, device %d)\n",
+ desc.idVendor, desc.idProduct,
+ libusb_get_bus_number(dev), libusb_get_device_address(dev));
+ }
+}
+
+int main(void)
+{
+ libusb_device **devs;
+ int r;
+ ssize_t cnt;
+
+ r = libusb_init(NULL);
+ if (r < 0)
+ return r;
+
+ cnt = libusb_get_device_list(NULL, &devs);
+ if (cnt < 0)
+ return (int) cnt;
+
+ print_devs(devs);
+ libusb_free_device_list(devs, 1);
+
+ libusb_exit(NULL);
+ return 0;
+}
+