summaryrefslogtreecommitdiffstats
path: root/usb.c
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2002-07-03 08:49:41 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2002-07-03 08:49:41 +0000
commit892e8372e001cb3b1035d05bf55fb391b5286cfa (patch)
tree6de8ba2ecda0fbd1558edbf056e8e758680c701a /usb.c
parentb020c90692263d1c432c35fc3d3be35de60f3f25 (diff)
downloadldetect-892e8372e001cb3b1035d05bf55fb391b5286cfa.tar
ldetect-892e8372e001cb3b1035d05bf55fb391b5286cfa.tar.gz
ldetect-892e8372e001cb3b1035d05bf55fb391b5286cfa.tar.bz2
ldetect-892e8372e001cb3b1035d05bf55fb391b5286cfa.tar.xz
ldetect-892e8372e001cb3b1035d05bf55fb391b5286cfa.zip
indent-region
Diffstat (limited to 'usb.c')
-rw-r--r--usb.c85
1 files changed, 43 insertions, 42 deletions
diff --git a/usb.c b/usb.c
index 4ecf398..6e6d36e 100644
--- a/usb.c
+++ b/usb.c
@@ -6,54 +6,55 @@
#include "common.h"
static int usb_find_modules(struct pciusb_entries entries) {
- return pciusb_find_modules(entries, "usbtable", 1 /* no_subid */);
+ return pciusb_find_modules(entries, "usbtable", 1 /* no_subid */);
}
extern struct pciusb_entries usb_probe(void) {
- FILE *f;
- char buf[512];
- int line;
- const char *file = "/proc/bus/usb/devices";
- struct pciusb_entry t[100];
- struct pciusb_entries r;
- struct pciusb_entry *e = NULL;
+ FILE *f;
+ char buf[512];
+ int line;
+ const char *file = "/proc/bus/usb/devices";
+ struct pciusb_entry t[100];
+ struct pciusb_entries r;
+ struct pciusb_entry *e = NULL;
- if (!(f = fopen(file, "r"))) exit(1);
+ if (!(f = fopen(file, "r")))
+ exit(1);
- for(r.nb = line = 0; fgets(buf, sizeof(buf) - 1, f) && r.nb < psizeof(t); line++) {
- if (buf[0] == 'P') {
- e = &t[r.nb++];
- pciusb_initialize(e);
+ for(r.nb = line = 0; fgets(buf, sizeof(buf) - 1, f) && r.nb < psizeof(t); line++) {
+ if (buf[0] == 'P') {
+ e = &t[r.nb++];
+ pciusb_initialize(e);
- if (sscanf(buf, "P: Vendor=%hx ProdID=%hx", &e->vendor, &e->device) != 2) {
- fprintf(stderr, "%s %d: unknown ``P'' line\n", file, line);
- pciusb_initialize(e);
- }
- } else if (e && buf[0] == 'I' && e->class_ == 0) {
- int class_, sub, prot = 0;
- if (sscanf(buf, "I: If#=%*2d Alt=%*2d #EPs=%*2d Cls=%02x(%*5c) Sub=%02x Prot=%02x", &class_, &sub, &prot) == 3) {
- e->class_ = (class_ * 0x100 + sub) * 0x100 + prot;
- } else {
- fprintf(stderr, "%s %d: unknown ``I'' line\n", file, line);
- }
- } else if (e && buf[0] == 'S') {
- int offset;
- char dummy;
- if (sscanf(buf, "S: Manufacturer=%n%c", &offset, &dummy) == 1) {
- buf[strlen(buf) - 1] = '|'; /* replacing '\n' by '|' */
- e->text = strdup(buf + offset);
- } else if (sscanf(buf, "S: Product=%n%c", &offset, &dummy) == 1) {
- if (!e->text) e->text = strdup("Unknown|");
- buf[strlen(buf) - 1] = 0; /* removing '\n' */
- e->text = realloc(e->text, strlen(e->text) + strlen(buf + offset) + 1);
- strcat(e->text, buf + offset);
- }
- }
- }
- fclose(f);
- r.entries = memdup(t, sizeof(struct pciusb_entry) * r.nb);
+ if (sscanf(buf, "P: Vendor=%hx ProdID=%hx", &e->vendor, &e->device) != 2) {
+ fprintf(stderr, "%s %d: unknown ``P'' line\n", file, line);
+ pciusb_initialize(e);
+ }
+ } else if (e && buf[0] == 'I' && e->class_ == 0) {
+ int class_, sub, prot = 0;
+ if (sscanf(buf, "I: If#=%*2d Alt=%*2d #EPs=%*2d Cls=%02x(%*5c) Sub=%02x Prot=%02x", &class_, &sub, &prot) == 3) {
+ e->class_ = (class_ * 0x100 + sub) * 0x100 + prot;
+ } else {
+ fprintf(stderr, "%s %d: unknown ``I'' line\n", file, line);
+ }
+ } else if (e && buf[0] == 'S') {
+ int offset;
+ char dummy;
+ if (sscanf(buf, "S: Manufacturer=%n%c", &offset, &dummy) == 1) {
+ buf[strlen(buf) - 1] = '|'; /* replacing '\n' by '|' */
+ e->text = strdup(buf + offset);
+ } else if (sscanf(buf, "S: Product=%n%c", &offset, &dummy) == 1) {
+ if (!e->text) e->text = strdup("Unknown|");
+ buf[strlen(buf) - 1] = 0; /* removing '\n' */
+ e->text = realloc(e->text, strlen(e->text) + strlen(buf + offset) + 1);
+ strcat(e->text, buf + offset);
+ }
+ }
+ }
+ fclose(f);
+ r.entries = memdup(t, sizeof(struct pciusb_entry) * r.nb);
- usb_find_modules(r);
- return r;
+ usb_find_modules(r);
+ return r;
}