aboutsummaryrefslogtreecommitdiff
path: root/util-linux/lsusb.c
diff options
context:
space:
mode:
authorSouf Oued <souf_oued@yahoo.fr>2009-12-07 01:37:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-12-07 01:37:34 +0100
commit11a802a0fa04627110809d908c588aa2c471d5aa (patch)
tree5e39c0017b7935e424106153e1031f0ac5f91f4d /util-linux/lsusb.c
parent982bc7176d04d9d3e2b40c4ddba24eab9f02dc4d (diff)
downloadbusybox-w32-11a802a0fa04627110809d908c588aa2c471d5aa.tar.gz
busybox-w32-11a802a0fa04627110809d908c588aa2c471d5aa.tar.bz2
busybox-w32-11a802a0fa04627110809d908c588aa2c471d5aa.zip
lsusb: new applet. +400 bytes
Signed-off-by: Souf Oued <souf_oued@yahoo.fr> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--util-linux/lsusb.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c
new file mode 100644
index 000000000..7c5b6b947
--- /dev/null
+++ b/util-linux/lsusb.c
@@ -0,0 +1,67 @@
1/* vi: set sw=4 ts=4: */
2/*
3* lspci implementation for busybox
4*
5* Copyright (C) 2009 Malek Degachi <malek-degachi@laposte.net>
6*
7* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
8*/
9#include <libbb.h>
10
11static int FAST_FUNC fileAction(
12 const char *fileName,
13 struct stat *statbuf UNUSED_PARAM,
14 void *userData UNUSED_PARAM,
15 int depth UNUSED_PARAM)
16{
17 parser_t *parser;
18 char *tokens[6];
19 char *bus = NULL, *device = NULL;
20 int product_vid = 0, product_did = 0;
21
22 char *uevent_filename = concat_path_file(fileName, "/uevent");
23 parser = config_open2(uevent_filename, fopen_for_read);
24 free(uevent_filename);
25
26 while (config_read(parser, tokens, 6, 1, "\\/=", PARSE_NORMAL)) {
27 if ((parser->lineno == 1) && strcmp(tokens[0], "DEVTYPE") == 0) {
28 break;
29 }
30
31 if (strcmp(tokens[0], "DEVICE") == 0) {
32 bus = xstrdup(tokens[4]);
33 device = xstrdup(tokens[5]);
34 continue;
35 }
36
37 if (strcmp(tokens[0], "PRODUCT") == 0) {
38 product_vid = xstrtou(tokens[1], 16);
39 product_did = xstrtou(tokens[2], 16);
40 continue;
41 }
42 }
43 config_close(parser);
44
45 if (bus) {
46 printf("Bus %s Device %s: ID %04x:%04x\n", bus, device, product_vid, product_did);
47 free(bus);
48 free(device);
49 }
50
51 return TRUE;
52}
53
54int lsusb_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
55int lsusb_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
56{
57 /* no options, no getopt */
58
59 recursive_action("/sys/bus/usb/devices",
60 ACTION_RECURSE,
61 fileAction,
62 NULL, /* dirAction */
63 NULL, /* userData */
64 0 /* depth */);
65
66 return EXIT_SUCCESS;
67}