[PCIIDS_PATH="$DEFAULT_PCIIDS_PATH"])
AC_DEFINE_DIR(PCIIDS_PATH, PCIIDS_PATH, [Path to pci.ids])
+AC_ARG_WITH(zlib,
+ AS_HELP_STRING([--with-zlib], [Enable zlib support to read gzip compressed pci.ids]),
+ [use_zlib="yes"],
+ [use_zlib="no"])
+if test "x$use_zlib" = xyes; then
+ AC_CHECK_LIB(z, gzopen,
+ [PCIACCESS_LIBS="$PCIACCESS_LIBS -lz"],
+ [AC_MSG_ERROR(Check for zlib library failed)])
+ AC_CHECK_HEADER([zlib.h],
+ [AC_DEFINE(HAVE_ZLIB, 1, [Use zlib to read gzip compressed pci.ids])],
+ [AC_MSG_ERROR(Check for zlib.h header file failed)])
+fi
+
if test "x$GCC" = "xyes"; then
GCC_WARNINGS1="-Wall -Wpointer-arith -Wstrict-prototypes"
GCC_WARNINGS2="-Wmissing-prototypes -Wmissing-declarations"
#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.
*
_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.
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;
* 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;
}
}
- fclose( f );
+ pci_id_file_close( f );
}