summaryrefslogtreecommitdiff
path: root/src/common_device_name.c
diff options
context:
space:
mode:
authorKel Modderman <kel@otaku42.de>2008-07-08 13:09:52 +0200
committerJulien Cristau <jcristau@debian.org>2008-07-08 13:22:23 +0200
commit45015ab30b36bdaefd3f3aeab73d287023928826 (patch)
tree71f7b423eb4d6df26487b256c0fc3b608263d6e6 /src/common_device_name.c
parent32c64bb2386c55d5c7a3878ae9e3f95577f00875 (diff)
downloadlibpciaccess-45015ab30b36bdaefd3f3aeab73d287023928826.tar.gz
libpciaccess-45015ab30b36bdaefd3f3aeab73d287023928826.tar.bz2
libpciaccess-45015ab30b36bdaefd3f3aeab73d287023928826.zip
Handle compressed pci.ids
Add an option to build with zlib support so we can find vendor/device information if the pci.ids file is gzipped. Signed-off-by: Julien Cristau <jcristau@debian.org>
Diffstat (limited to 'src/common_device_name.c')
-rw-r--r--src/common_device_name.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/common_device_name.c b/src/common_device_name.c
index b105187..877f218 100644
--- a/src/common_device_name.c
+++ b/src/common_device_name.c
@@ -50,6 +50,31 @@
#define DO_MATCH(a,b) (((a) == PCI_MATCH_ANY) || ((a) == (b)))
+#ifdef HAVE_ZLIB
+#include <zlib.h>
+typedef gzFile pci_id_file;
+
+static pci_id_file
+pci_id_file_open()
+{
+ pci_id_file result;
+
+ result = gzopen(PCIIDS_PATH "/pci.ids.gz", "rb");
+ if (result)
+ return result;
+
+ return gzopen(PCIIDS_PATH "/pci.ids", "rb");
+}
+
+#define pci_id_file_gets(l, s, f) gzgets(f, l, s)
+#define pci_id_file_close(f) gzclose(f)
+#else
+typedef FILE pci_id_file;
+#define pci_id_file_open() fopen(PCIIDS_PATH "/pci.ids", "r")
+#define pci_id_file_gets(l, s, f) fgets(l, s, f)
+#define pci_id_file_close(f) fclose(f)
+#endif
+
/**
* Node for sorting vendor IDs.
*
@@ -96,12 +121,6 @@ struct pci_device_leaf {
_pci_hidden struct pci_id_node * tree = NULL;
/**
- * Name of the file containing the PCI ID information.
- */
-static const char pci_id_file[] = PCIIDS_PATH "/pci.ids";
-
-
-/**
* Get a pointer to the leaf node for a vendor ID.
*
* If the vendor ID does not exist in the tree, it is added.
@@ -170,7 +189,7 @@ insert( uint16_t vendor )
static void
populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
{
- FILE * f = fopen( pci_id_file, "r" );
+ pci_id_file * f = pci_id_file_open();
char buf[128];
unsigned vendor = PCI_MATCH_ANY;
@@ -186,12 +205,12 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
* anything. This avoids wasted processing and potential memory leaks.
*/
if (vend->num_devices != 0) {
- fclose(f);
+ pci_id_file_close( f );
return;
}
- while( fgets( buf, sizeof( buf ), f ) != NULL ) {
+ while( pci_id_file_gets( buf, sizeof( buf ), f ) != NULL ) {
unsigned num_tabs;
char * new_line;
size_t length;
@@ -284,7 +303,7 @@ populate_vendor( struct pci_id_leaf * vend, int fill_device_data )
}
}
- fclose( f );
+ pci_id_file_close( f );
}