]> mj.ucw.cz Git - pciutils.git/blob - common.c
2.1.99-test1 released
[pciutils.git] / common.c
1 /*
2  *      Linux PCI Utilities -- Common Functions
3  *
4  *      Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
5  *
6  *      Can be freely distributed and used under the terms of the GNU GPL.
7  */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include <stdarg.h>
13 #include <unistd.h>
14
15 #include "pciutils.h"
16
17 void NONRET
18 die(char *msg, ...)
19 {
20   va_list args;
21
22   va_start(args, msg);
23   fputs("lspci: ", stderr);
24   vfprintf(stderr, msg, args);
25   fputc('\n', stderr);
26   exit(1);
27 }
28
29 void *
30 xmalloc(unsigned int howmuch)
31 {
32   void *p = malloc(howmuch);
33   if (!p)
34     die("Unable to allocate %d bytes of memory", howmuch);
35   return p;
36 }
37
38 int
39 parse_generic_option(int i, struct pci_access *pacc, char *optarg)
40 {
41   switch (i)
42     {
43 #ifdef HAVE_PM_LINUX_PROC
44     case 'P':
45       pacc->method_params[PCI_ACCESS_PROC_BUS_PCI] = optarg;
46       pacc->method = PCI_ACCESS_PROC_BUS_PCI;
47       break;
48 #endif
49 #ifdef HAVE_PM_INTEL_CONF
50     case 'H':
51       if (!strcmp(optarg, "1"))
52         pacc->method = PCI_ACCESS_I386_TYPE1;
53       else if (!strcmp(optarg, "2"))
54         pacc->method = PCI_ACCESS_I386_TYPE2;
55       else
56         die("Unknown hardware configuration type %s", optarg);
57       break;
58 #endif
59 #ifdef HAVE_PM_DUMP
60     case 'F':
61       pacc->method_params[PCI_ACCESS_DUMP] = optarg;
62       pacc->method = PCI_ACCESS_DUMP;
63       break;
64 #endif
65     case 'G':
66       pacc->debugging++;
67       break;
68     default:
69       return 0;
70     }
71   return 1;
72 }