From 2d238c511327c768081c77c11ef4ab5a8ee074d1 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Thu, 4 Jul 2002 15:14:00 +0000 Subject: - factorize common constants in private header - factorize strlen() call --- usb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usb.c b/usb.c index f7c2c7e..176df6a 100644 --- a/usb.c +++ b/usb.c @@ -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); } } -- cgit v1.2.1