Annotation of embedaddon/pciutils/lib/params.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  *     The PCI Library -- Parameters
        !             3:  *
        !             4:  *     Copyright (c) 2008 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 <stdlib.h>
        !            11: #include <string.h>
        !            12: 
        !            13: #include "internal.h"
        !            14: 
        !            15: char *
        !            16: pci_get_param(struct pci_access *acc, char *param)
        !            17: {
        !            18:   struct pci_param *p;
        !            19: 
        !            20:   for (p=acc->params; p; p=p->next)
        !            21:     if (!strcmp(p->param, param))
        !            22:       return p->value;
        !            23:   return NULL;
        !            24: }
        !            25: 
        !            26: void
        !            27: pci_define_param(struct pci_access *acc, char *param, char *value, char *help)
        !            28: {
        !            29:   struct pci_param *p = pci_malloc(acc, sizeof(*p));
        !            30: 
        !            31:   p->next = acc->params;
        !            32:   acc->params = p;
        !            33:   p->param = param;
        !            34:   p->value = value;
        !            35:   p->value_malloced = 0;
        !            36:   p->help = help;
        !            37: }
        !            38: 
        !            39: int
        !            40: pci_set_param_internal(struct pci_access *acc, char *param, char *value, int copy)
        !            41: {
        !            42:   struct pci_param *p;
        !            43: 
        !            44:   for (p=acc->params; p; p=p->next)
        !            45:     if (!strcmp(p->param, param))
        !            46:       {
        !            47:        if (p->value_malloced)
        !            48:          pci_mfree(p->value);
        !            49:        p->value_malloced = copy;
        !            50:        if (copy)
        !            51:          p->value = pci_strdup(acc, value);
        !            52:        else
        !            53:          p->value = value;
        !            54:        return 0;
        !            55:       }
        !            56:   return -1;
        !            57: }
        !            58: 
        !            59: int
        !            60: pci_set_param(struct pci_access *acc, char *param, char *value)
        !            61: {
        !            62:   return pci_set_param_internal(acc, param, value, 1);
        !            63: }
        !            64: 
        !            65: void
        !            66: pci_free_params(struct pci_access *acc)
        !            67: {
        !            68:   struct pci_param *p;
        !            69: 
        !            70:   while (p = acc->params)
        !            71:     {
        !            72:       acc->params = p->next;
        !            73:       if (p->value_malloced)
        !            74:        pci_mfree(p->value);
        !            75:       pci_mfree(p);
        !            76:     }
        !            77: }
        !            78: 
        !            79: struct pci_param *
        !            80: pci_walk_params(struct pci_access *acc, struct pci_param *prev)
        !            81: {
        !            82:   /* So far, the params form a simple linked list, but this can change in the future */
        !            83:   if (!prev)
        !            84:     return acc->params;
        !            85:   else
        !            86:     return prev->next;
        !            87: }
        !            88: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>