summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2005-08-26 07:15:04 +0000
committerDaniel Stone <daniel@fooishbar.org>2005-08-26 07:15:04 +0000
commitbb5e934df7f23fb365ed673a12d283ff52af79c0 (patch)
treec01b15c1eb839b36cec1d2497f5b4d4586e84411
parentc937faadd0a0a5f2598b84286ac1ed8996a512e5 (diff)
downloadxserver-bb5e934df7f23fb365ed673a12d283ff52af79c0.tar.gz
Only open /proc/bus/pci/devices once. (Ubuntu #029)
-rw-r--r--hw/xfree86/os-support/linux/lnx_pci.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/hw/xfree86/os-support/linux/lnx_pci.c b/hw/xfree86/os-support/linux/lnx_pci.c
index 97edd11a6..1b74fcbbd 100644
--- a/hw/xfree86/os-support/linux/lnx_pci.c
+++ b/hw/xfree86/os-support/linux/lnx_pci.c
@@ -23,10 +23,11 @@
#define PCIADDR_FMT "%lx"
#endif
+FILE *xf86OSLinuxPCIFile = NULL;
+
Bool
xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
{
- FILE *file;
char c[0x200];
char *res;
unsigned int bus, devfn, dev, fn;
@@ -37,10 +38,11 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
if (index > 7)
return FALSE;
- if (!(file = fopen("/proc/bus/pci/devices","r")))
+ if (!xf86OSLinuxPCIFile && \
+ !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r")))
return FALSE;
do {
- res = fgets(c,0x1ff,file);
+ res = fgets(c,0x1ff,xf86OSLinuxPCIFile);
if (res) {
num = sscanf(res,
/*bus+dev vendorid deviceid irq */
@@ -64,7 +66,7 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
&bus,&devfn,&size[0],&size[1],&size[2],&size[3],
&size[4],&size[5],&size[6]);
if (num != 9) { /* apparantly not 2.3 style */
- fclose(file);
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
return FALSE;
}
dev = devfn >> 3;
@@ -78,13 +80,13 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
(*bits)++;
}
}
- fclose(file);
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
return TRUE;
}
}
} while (res);
- fclose(file);
+ fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET);
return FALSE;
}