2 * The PCI Utilities -- Common Functions
4 * Copyright (c) 1997--2016 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+.
8 * SPDX-License-Identifier: GPL-2.0-or-later
24 fprintf(stderr, "%s: ", program_name);
25 vfprintf(stderr, msg, args);
31 xmalloc(size_t howmuch)
33 void *p = malloc(howmuch);
35 die("Unable to allocate %d bytes of memory", (int) howmuch);
40 xrealloc(void *ptr, size_t howmuch)
42 void *p = realloc(ptr, howmuch);
44 die("Unable to allocate %d bytes of memory", (int) howmuch);
49 xstrdup(const char *str)
51 int len = strlen(str) + 1;
52 char *copy = xmalloc(len);
53 memcpy(copy, str, len);
58 set_pci_method(struct pci_access *pacc, char *arg)
63 if (!strcmp(arg, "help"))
65 printf("Known PCI access methods:\n\n");
66 for (i=0; name = pci_get_method_name(i); i++)
73 i = pci_lookup_method(arg);
75 die("No such PCI access method: %s (see `-A help' for a list)", arg);
81 set_pci_option(struct pci_access *pacc, char *arg)
83 if (!strcmp(arg, "help"))
86 printf("Known PCI access parameters:\n\n");
87 for (p=NULL; p=pci_walk_params(pacc, p);)
88 printf("%-20s %s (%s)\n", p->param, p->help, p->value);
93 char *sep = strchr(arg, '=');
95 die("Invalid PCI access parameter syntax: %s", arg);
97 if (pci_set_param(pacc, arg, sep) < 0)
98 die("Unrecognized PCI access parameter: %s (see `-O help' for a list)", arg);
103 parse_generic_option(int i, struct pci_access *pacc, char *arg)
107 #ifdef PCI_HAVE_PM_INTEL_CONF
109 if (!strcmp(arg, "1"))
110 pacc->method = PCI_ACCESS_I386_TYPE1;
111 else if (!strcmp(arg, "2"))
112 pacc->method = PCI_ACCESS_I386_TYPE2;
114 die("Unknown hardware configuration type %s", arg);
117 #ifdef PCI_HAVE_PM_DUMP
119 pci_set_param(pacc, "dump.name", arg);
120 pacc->method = PCI_ACCESS_DUMP;
124 set_pci_method(pacc, arg);
130 set_pci_option(pacc, arg);