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