summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.com>2007-08-15 00:22:36 +0000
committerOlivier Blin <oblin@mandriva.com>2007-08-15 00:22:36 +0000
commit79a055cf4c8f83e8a9183de150d5906d1ff75476 (patch)
tree9521d0adfb53fdb70a81e4edeb09e22d1aaf81b6 /common.c
parent472e665be19dc391f26787bd2c73d38cdbb133b5 (diff)
downloadldetect-79a055cf4c8f83e8a9183de150d5906d1ff75476.tar
ldetect-79a055cf4c8f83e8a9183de150d5906d1ff75476.tar.gz
ldetect-79a055cf4c8f83e8a9183de150d5906d1ff75476.tar.bz2
ldetect-79a055cf4c8f83e8a9183de150d5906d1ff75476.tar.xz
ldetect-79a055cf4c8f83e8a9183de150d5906d1ff75476.zip
use zlib to read gzipped files instead of piping gzip command
Diffstat (limited to 'common.c')
-rw-r--r--common.c61
1 files changed, 14 insertions, 47 deletions
diff --git a/common.c b/common.c
index 01ebae9..0f17cc7 100644
--- a/common.c
+++ b/common.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <zlib.h>
#include "common.h"
static char *table_name_to_file(const char *name) {
@@ -15,60 +16,26 @@ static char *table_name_to_file(const char *name) {
if (!share_path || !*share_path) share_path = "/usr/share";
asprintf(&fname, "%s/ldetect-lst/%s", share_path, name);
+
return fname;
}
fh fh_open(const char *name) {
- fh ret;
char *fname = table_name_to_file(name);
- int length = strlen(fname);
-
- if (access(fname, R_OK) == 0) {
- 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) {
- fprintf(stderr, "Missing %s (should be %s)\n", name, 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[5];
- int ip = 0;
- char *ld_loader = getenv("LD_LOADER");
-
- if (ld_loader && *ld_loader)
- cmd[ip++] = ld_loader;
- cmd[ip++] = "gzip";
- cmd[ip++] = "-cd";
- cmd[ip++] = fname_gz;
- cmd[ip++] = NULL;
+ if (access(fname, R_OK) != 0) {
+ char *fname_gz;
+ asprintf(&fname_gz, "%s.gz", fname);
+ free(fname);
+ fname = fname_gz;
+ }
- dup2(fdno[1], STDOUT_FILENO);
- close(fdno[0]);
- close(fdno[1]);
- execvp(cmd[0], cmd);
- perror("pciusb");
- exit(2);
- }
+ fh f = gzopen(fname, "r");
+ if (!f) {
+ perror("pciusb");
+ exit(1);
}
- free(fname);
- return ret;
-}
-void fh_close(fh *f) {
- fclose(f->f);
- if (f->pid > 0)
- waitpid(f->pid, NULL, 0);
+ free(fname);
+ return f;
}