summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2002-07-03 10:01:03 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2002-07-03 10:01:03 +0000
commitafc7ac83ff5055538f7f8972d1355592968049e6 (patch)
tree4987209a7cd0e2c8e808d0ea585d3fac199ae834
parent8f71ad0e632704ce7a5b0480efbb87299c85b079 (diff)
downloadldetect-afc7ac83ff5055538f7f8972d1355592968049e6.tar
ldetect-afc7ac83ff5055538f7f8972d1355592968049e6.tar.gz
ldetect-afc7ac83ff5055538f7f8972d1355592968049e6.tar.bz2
ldetect-afc7ac83ff5055538f7f8972d1355592968049e6.tar.xz
ldetect-afc7ac83ff5055538f7f8972d1355592968049e6.zip
- make gzip path in fh_open() be clearer
- pciusb_find_modules() optimization / cleanups : - only calc module and description once so that if there're multiples identical cards, we just gives the same result - do less copies : - only copy when setting e->{text,module} - it's useless to do copies on the stack, just play with strndup() instead of strdup() - skip comments in {usb,pci}table - remove if (q) test which is uneeded since we've already parsed the buffer with sscanf() and we've skipped comments - remove uneeded ifree (it's impossible to get valid pointer a this point)
-rw-r--r--pciusb.c75
1 files changed, 39 insertions, 36 deletions
diff --git a/pciusb.c b/pciusb.c
index 0c66c1d..405a9ee 100644
--- a/pciusb.c
+++ b/pciusb.c
@@ -26,38 +26,38 @@ static fh fh_open(char *fname) {
ret.f = fopen(fname, "r");
ret.pid = 0;
} else {
+ int fdno[2];
char *fname_gz = alloca(length + sizeof(".gz"));
sprintf(fname_gz, "%s.gz", fname);
- if (access(fname_gz, R_OK) == 0) {
- int fdno[2];
- if (pipe(fdno)) {
- perror("pciusb"); exit(1);
- }
- if ((ret.pid = fork()) != 0) {
- ret.f = fdopen(fdno[0], "r");
- close(fdno[1]);
- } else {
- char* cmd[4];
- int ip = 0;
- char *ld_loader = getenv("LD_LOADER");
-
- if (ld_loader && *ld_loader)
- cmd[ip++] = ld_loader;
-
- cmd[ip++] = "zcat";
- cmd[ip++] = fname_gz;
- cmd[ip++] = NULL;
-
- dup2(fdno[1], STDOUT_FILENO);
- close(fdno[0]);
- close(fdno[1]);
- execvp(cmd[0], cmd);
- perror("pciusb"); exit(2);
- }
- } else {
+ if (access(fname_gz, R_OK) != 0) {
fprintf(stderr, "Missing pciusbtable (should be %s)\n", fname);
exit(1);
}
+ if (pipe(fdno))
+ perror("pciusb"); exit(1);
+
+ if ((ret.pid = fork()) != 0) {
+ ret.f = fdopen(fdno[0], "r");
+ close(fdno[1]);
+ } else {
+ char* cmd[4];
+ int ip = 0;
+ char *ld_loader = getenv("LD_LOADER");
+
+ if (ld_loader && *ld_loader)
+ cmd[ip++] = ld_loader;
+
+ cmd[ip++] = "zcat";
+ cmd[ip++] = fname_gz;
+ cmd[ip++] = NULL;
+
+ dup2(fdno[1], STDOUT_FILENO);
+ close(fdno[0]);
+ close(fdno[1]);
+ execvp(cmd[0], cmd);
+ perror("pciusb");
+ exit(2);
+ }
}
return ret;
}
@@ -84,8 +84,13 @@ extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciu
for (line = 1; fgets(buf, sizeof(buf) - 1, f.f); line++) {
unsigned short vendor, device, subvendor, subdevice;
+ char *p = NULL, *q = NULL;
int offset; unsigned int i;
- int nb = sscanf(buf, "0x%hx\t0x%hx\t0x%hx\t0x%hx\t%n", &vendor, &device, &subvendor, &subdevice, &offset);
+ int nb;
+ if (buf[0]=='#')
+ continue; // skip comments
+
+ nb = sscanf(buf, "0x%hx\t0x%hx\t0x%hx\t0x%hx\t%n", &vendor, &device, &subvendor, &subdevice, &offset);
if (nb != 4) {
nb = sscanf(buf, "0x%hx\t0x%hx\t%n", &vendor, &device, &offset);
if (nb != 2) {
@@ -104,15 +109,13 @@ extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciu
}
if ((nb != 4 || (subvendor == e->subvendor && subdevice == e->subdevice)) && !e->module) {
- char *p = strdupa(buf + offset + 1);
- char *q = strchr(p, '\t');
- if (q) {
- q[-1] = 0;
- q[strlen(q)-2] = 0;
- ifree(e->module); ifree(e->text);
- e->module = strcmp(p, "unknown") ? strdup(p) : NULL;
- e->text = strdup(q+2);
+ if (!p) {
+ /* only do that search if not already done */
+ p = buf + offset + 1;
+ q = strchr(p, '\t');
}
+ e->module = strcmp(p, "unknown") ? strndup(p,q-p-1) : NULL;
+ e->text = strndup(q+2, strlen(q)-4);
}
}
}