diff options
author | Olivier Blin <oblin@mandriva.com> | 2008-02-27 16:11:15 +0000 |
---|---|---|
committer | Olivier Blin <oblin@mandriva.com> | 2008-02-27 16:11:15 +0000 |
commit | 687c1d1454898339b5cf00654359a326089ffccd (patch) | |
tree | 72143e9b83b86f114c528186f071711bc86cf205 | |
parent | 606fb4b58d31c17c91eb2eb57c7eda76fd1f86a1 (diff) | |
download | ldetect-687c1d1454898339b5cf00654359a326089ffccd.tar ldetect-687c1d1454898339b5cf00654359a326089ffccd.tar.gz ldetect-687c1d1454898339b5cf00654359a326089ffccd.tar.bz2 ldetect-687c1d1454898339b5cf00654359a326089ffccd.tar.xz ldetect-687c1d1454898339b5cf00654359a326089ffccd.zip |
allow to modify the fh type more easily by adding more wrappers
-rw-r--r-- | common.c | 19 | ||||
-rw-r--r-- | common.h | 8 | ||||
-rw-r--r-- | dmi.c | 4 | ||||
-rw-r--r-- | pciusb.c | 4 |
4 files changed, 25 insertions, 10 deletions
@@ -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; } @@ -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 @@ -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; @@ -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) |