diff options
author | Thierry Vignaud <tvignaud@mandriva.org> | 2002-07-04 15:14:00 +0000 |
---|---|---|
committer | Thierry Vignaud <tvignaud@mandriva.org> | 2002-07-04 15:14:00 +0000 |
commit | 2d238c511327c768081c77c11ef4ab5a8ee074d1 (patch) | |
tree | 59f390e9b582e2b311e01d9ef9754df97ef8103c /usb.c | |
parent | b303bba5f90b53d1385c413f2c2da47c38a42b9c (diff) | |
download | ldetect-2d238c511327c768081c77c11ef4ab5a8ee074d1.tar ldetect-2d238c511327c768081c77c11ef4ab5a8ee074d1.tar.gz ldetect-2d238c511327c768081c77c11ef4ab5a8ee074d1.tar.bz2 ldetect-2d238c511327c768081c77c11ef4ab5a8ee074d1.tar.xz ldetect-2d238c511327c768081c77c11ef4ab5a8ee074d1.zip |
- factorize common constants in private header
- factorize strlen() call
Diffstat (limited to 'usb.c')
-rw-r--r-- | usb.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -8,7 +8,7 @@ extern struct pciusb_entries usb_probe(void) { FILE *f; - char buf[512]; + char buf[BUF_SIZE]; int line; const char *file = "/proc/bus/usb/devices"; struct pciusb_entry t[MAX_DEVICES]; @@ -37,14 +37,15 @@ extern struct pciusb_entries usb_probe(void) { } else if (e && buf[0] == 'S') { int offset; char dummy; + size_t length = strlen(buf) -1; if (sscanf(buf, "S: Manufacturer=%n%c", &offset, &dummy) == 1) { - buf[strlen(buf) - 1] = '|'; /* replacing '\n' by '|' */ + buf[length] = '|'; /* 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); + buf[length - 1] = 0; /* removing '\n' */ + e->text = realloc(e->text, strlen(e->text) + length-offset) + 2); strcat(e->text, buf + offset); } } |