summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common.c19
-rw-r--r--common.h8
-rw-r--r--dmi.c4
-rw-r--r--pciusb.c4
4 files changed, 25 insertions, 10 deletions
diff --git a/common.c b/common.c
index e296d7f..66cc6d8 100644
--- a/common.c
+++ b/common.c
@@ -20,6 +20,7 @@ char *table_name_to_file(const char *name) {
}
fh fh_open(const char *name) {
+ fh ret;
char *fname = table_name_to_file(name);
if (access(fname, R_OK) != 0) {
@@ -29,12 +30,24 @@ fh fh_open(const char *name) {
fname = fname_gz;
}
- fh f = gzopen(fname, "r");
- if (!f) {
+ ret.zlib_fh = gzopen(fname, "r");
+ if (!ret.zlib_fh) {
perror("pciusb");
exit(1);
}
free(fname);
- return f;
+ return ret;
+}
+
+char* fh_gets(char *line, int size, fh *f) {
+ char *ret;
+ ret = gzgets(f->zlib_fh, line, size);
+ return ret;
+}
+
+int fh_close(fh *f) {
+ int ret;
+ ret = gzclose(f->zlib_fh);
+ return ret;
}
diff --git a/common.h b/common.h
index e114533..8f79471 100644
--- a/common.h
+++ b/common.h
@@ -21,14 +21,16 @@ extern void pciusb_initialize(struct pciusb_entry *e) NON_EXPORTED;
#define MAX_DEVICES 100
#define BUF_SIZE 512
+typedef struct {
+ gzFile zlib_fh;
+} fh;
#define psizeof(a) (sizeof(a) / sizeof(*(a)))
#define ifree(p) do { if (p) { free(p); p = NULL; } } while (0)
-typedef gzFile fh;
extern fh fh_open(const char *name) NON_EXPORTED;
+extern char* fh_gets(char *line, int size, fh *f) NON_EXPORTED;
+extern int fh_close(fh *f) NON_EXPORTED;
#pragma GCC visibility pop
-#define fh_gets(line, size, f) gzgets(f, line, size)
-#define fh_close(f) gzclose(f);
#endif
diff --git a/dmi.c b/dmi.c
index b0df357..d316ed2 100644
--- a/dmi.c
+++ b/dmi.c
@@ -195,7 +195,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) {
int previous_refine = 0;
- for (line = 1; fh_gets(buf, sizeof(buf) - 1, f); line++) {
+ for (line = 1; fh_gets(buf, sizeof(buf) - 1, &f); line++) {
char *s = skip_leading_spaces(buf);
if (*s == '#') continue; // skip comments
@@ -261,7 +261,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) {
}
}
foreach_indent(0, ifree(constraints[i]));
- fh_close(f);
+ fh_close(&f);
realloc(r.entries, sizeof(*r.entries) * r.nb);
return r;
diff --git a/pciusb.c b/pciusb.c
index 7dc373f..28ab984 100644
--- a/pciusb.c
+++ b/pciusb.c
@@ -109,7 +109,7 @@ extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciu
f = fh_open(fpciusbtable);
- for (line = 1; fh_gets(buf, sizeof(buf) - 1, f); line++) {
+ for (line = 1; fh_gets(buf, sizeof(buf) - 1, &f); line++) {
unsigned short vendor, device, subvendor, subdevice;
char *p = NULL, *q = NULL;
int offset; unsigned int i;
@@ -156,7 +156,7 @@ extern int pciusb_find_modules(struct pciusb_entries *entries, const char *fpciu
e->already_found = 1;
}
}
- fh_close(f);
+ fh_close(&f);
/* If no special case in pcitable, then lookup modalias for PCI devices
(USB are already done by kernel)