-void *
-xmalloc(unsigned int howmuch)
-{
- void *p = malloc(howmuch);
- if (!p)
- {
- fprintf(stderr, "setpci: Unable to allocate %d bytes of memory\n", howmuch);
- exit(1);
- }
- return p;
-}
-
-/*
- * As libc doesn't support pread/pwrite yet, we have to call them directly
- * or use lseek/read/write instead.
- */
-#if !(defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0)
-
-#if defined(__GLIBC__) && !(defined(__powerpc__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 0)
-#ifndef SYS_pread
-#define SYS_pread __NR_pread
-#endif
-static int
-pread(unsigned int fd, void *buf, size_t size, loff_t where)
-{
- return syscall(SYS_pread, fd, buf, size, where);
-}
-
-#ifndef SYS_pwrite
-#define SYS_pwrite __NR_pwrite
-#endif
-static int
-pwrite(unsigned int fd, void *buf, size_t size, loff_t where)
-{
- return syscall(SYS_pwrite, fd, buf, size, where);
-}
-#else
-static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
-static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where);
-#endif
-
-#endif
-
-static void
-scan_devices(void)
-{
- struct device **last = &first_dev;
- byte line[256];
- FILE *f;
-
- if (!(f = fopen(PROC_BUS_PCI "/devices", "r")))
- {
- perror(PROC_BUS_PCI "/devices");
- exit(1);
- }
- while (fgets(line, sizeof(line), f))
- {
- struct device *d = xmalloc(sizeof(struct device));
- unsigned int dfn, vend;
-
- sscanf(line, "%x %x", &dfn, &vend);
- d->bus = dfn >> 8U;
- d->devfn = dfn & 0xff;
- d->vendid = vend >> 16U;
- d->devid = vend & 0xffff;
- d->fd = -1;
- *last = d;
- last = &d->next;
- }
- fclose(f);
- *last = NULL;
-}
-
-static struct device **