diff options
author | Olivier Blin <oblin@mandriva.com> | 2008-02-27 16:56:26 +0000 |
---|---|---|
committer | Olivier Blin <oblin@mandriva.com> | 2008-02-27 16:56:26 +0000 |
commit | 9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f (patch) | |
tree | cb9e8cdb953113e705bfe269c33e339b451c56be | |
parent | fc9e5d6e7674094758d7d8af6e6e05edc62b8519 (diff) | |
download | ldetect-9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f.tar ldetect-9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f.tar.gz ldetect-9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f.tar.bz2 ldetect-9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f.tar.xz ldetect-9d2ba8eff2e67f8e9abd0885bc2af3ac91d3369f.zip |
extract find_modalias function
-rw-r--r-- | pciusb.c | 49 |
1 files changed, 28 insertions, 21 deletions
@@ -19,6 +19,31 @@ static const char *config = NULL; static char *aliasfilename, *symfilename; +static char *find_modalias(struct pciusb_entry *e) { + char *modalias = NULL; + char *modalias_path; + FILE *file; + asprintf(&modalias_path, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/modalias", e->pci_domain, e->pci_bus, e->pci_device, e->pci_function); + file = fopen(modalias_path, "r"); + if (file) { + size_t n, size; + if (-1 == getline(&modalias, &n, file)) { + fprintf(stderr, "Unable to read modalias from %s\n", modalias_path); + fclose(file); + return NULL; + } + fclose(file); + size = strlen(modalias); + if (size) + modalias[size-1] = 0; + } else { + fprintf(stderr, "Unable to read modalias from %s\n", modalias_path); + return NULL; + } + free(modalias_path); + return modalias; +} + static void find_modules_through_aliases(struct pciusb_entries *entries) { unsigned int i; char *dirname; @@ -45,27 +70,9 @@ static void find_modules_through_aliases(struct pciusb_entries *entries) { if (e->module && strcmp(e->module, "unknown")) continue; - char *modalias = NULL; - char *modalias_path; - FILE *file; - asprintf(&modalias_path, "/sys/bus/pci/devices/%04x:%02x:%02x.%x/modalias", e->pci_domain, e->pci_bus, e->pci_device, e->pci_function); - file = fopen(modalias_path, "r"); - if (file) { - size_t n, size; - if (-1 == getline(&modalias, &n, file)) { - fprintf(stderr, "Unable to read modalias from %s\n", modalias_path); - fclose(file); - continue; - } - fclose(file); - size = strlen(modalias); - if (size) - modalias[size-1] = 0; - } else { - fprintf(stderr, "Unable to read modalias from %s\n", modalias_path); - continue; - } - free(modalias_path); + char *modalias = find_modalias(e); + if (!modalias) + continue; /* Returns the resolved alias, options */ read_toplevel_config(config, modalias, 0, |