X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fparams.c;h=ac756ad79a313661e13f3d67cf85ec5e3cd43bf6;hb=93c1c6bcc9e2b52652b859986354ddd54ef34058;hp=0e6edbb03f85c4e3034c57a1bf0a0a40d776554e;hpb=d6dcc545806168d496ecc52ca52603fdc0dfd395;p=pciutils.git diff --git a/lib/params.c b/lib/params.c index 0e6edbb..ac756ad 100644 --- a/lib/params.c +++ b/lib/params.c @@ -1,9 +1,11 @@ /* * The PCI Library -- Parameters * - * Copyright (c) 2008 Martin Mares + * Copyright (c) 2008--2023 Martin Mares * - * Can be freely distributed and used under the terms of the GNU GPL. + * Can be freely distributed and used under the terms of the GNU GPL v2+. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ #include @@ -26,10 +28,24 @@ pci_get_param(struct pci_access *acc, char *param) void pci_define_param(struct pci_access *acc, char *param, char *value, char *help) { - struct pci_param *p = pci_malloc(acc, sizeof(*p)); + struct pci_param *p, **pp; - p->next = acc->params; - acc->params = p; + for (pp=&acc->params; p = *pp; pp=&p->next) + { + int cmp = strcmp(p->param, param); + if (!cmp) + { + if (strcmp(p->value, value) || strcmp(p->help, help)) + acc->error("Parameter %s re-defined differently", param); + return; + } + if (cmp > 0) + break; + } + + p = pci_malloc(acc, sizeof(*p)); + p->next = *pp; + *pp = p; p->param = param; p->value = value; p->value_malloced = 0; @@ -85,4 +101,3 @@ pci_walk_params(struct pci_access *acc, struct pci_param *prev) else return prev->next; } -