X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=common.c;h=3d69dd0b4a5ab45384fa4f86f76147f3445a3b0e;hb=0766bfa0f557430a6dd3256d45a5b756499f9f7b;hp=ed39b87148f6c726178f206f460c39c39975c56f;hpb=90f8c88626289b0a713abc41759e8bebe6c20ddb;p=pciutils.git diff --git a/common.c b/common.c index ed39b87..3d69dd0 100644 --- a/common.c +++ b/common.c @@ -1,7 +1,7 @@ /* * The PCI Utilities -- Common Functions * - * Copyright (c) 1997--2008 Martin Mares + * Copyright (c) 1997--2016 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -10,7 +10,6 @@ #include #include #include -#include #include "pciutils.h" @@ -27,23 +26,32 @@ die(char *msg, ...) } void * -xmalloc(unsigned int howmuch) +xmalloc(size_t howmuch) { void *p = malloc(howmuch); if (!p) - die("Unable to allocate %d bytes of memory", howmuch); + die("Unable to allocate %d bytes of memory", (int) howmuch); return p; } void * -xrealloc(void *ptr, unsigned int howmuch) +xrealloc(void *ptr, size_t howmuch) { void *p = realloc(ptr, howmuch); if (!p) - die("Unable to allocate %d bytes of memory", howmuch); + die("Unable to allocate %d bytes of memory", (int) howmuch); return p; } +char * +xstrdup(const char *str) +{ + int len = strlen(str) + 1; + char *copy = xmalloc(len); + memcpy(copy, str, len); + return copy; +} + static void set_pci_method(struct pci_access *pacc, char *arg) { @@ -90,34 +98,34 @@ set_pci_option(struct pci_access *pacc, char *arg) } int -parse_generic_option(int i, struct pci_access *pacc, char *optarg) +parse_generic_option(int i, struct pci_access *pacc, char *arg) { switch (i) { #ifdef PCI_HAVE_PM_INTEL_CONF case 'H': - if (!strcmp(optarg, "1")) + if (!strcmp(arg, "1")) pacc->method = PCI_ACCESS_I386_TYPE1; - else if (!strcmp(optarg, "2")) + else if (!strcmp(arg, "2")) pacc->method = PCI_ACCESS_I386_TYPE2; else - die("Unknown hardware configuration type %s", optarg); + die("Unknown hardware configuration type %s", arg); break; #endif #ifdef PCI_HAVE_PM_DUMP case 'F': - pci_set_param(pacc, "dump.name", optarg); + pci_set_param(pacc, "dump.name", arg); pacc->method = PCI_ACCESS_DUMP; break; #endif case 'A': - set_pci_method(pacc, optarg); + set_pci_method(pacc, arg); break; case 'G': pacc->debugging++; break; case 'O': - set_pci_option(pacc, optarg); + set_pci_option(pacc, arg); break; default: return 0;