diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-09-24 04:28:45 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-09-24 04:28:45 +0200 |
commit | 08a01723af9cd52c078d5ca6c38c34d375b39fa0 (patch) | |
tree | 6eadea9c67f4bb56a9e4ee09f4982efaf61deece /pcilib/unit.c | |
parent | 924adedb2928f5657c6668f606dbb3294b3c45da (diff) | |
parent | ae7f83a7948d8c3760f8019899a45e6ec90c2c6a (diff) | |
download | pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.gz pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.bz2 pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.tar.xz pcitool-08a01723af9cd52c078d5ca6c38c34d375b39fa0.zip |
Finalyze XML support and provide initial support for views (only descriptions so far)
Diffstat (limited to 'pcilib/unit.c')
-rw-r--r-- | pcilib/unit.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/pcilib/unit.c b/pcilib/unit.c new file mode 100644 index 0000000..2dd7113 --- /dev/null +++ b/pcilib/unit.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> + +#include "pci.h" +#include "pcilib.h" +#include "unit.h" +#include "error.h" + + +pcilib_unit_t pcilib_find_unit_by_name(pcilib_t *ctx, const char *unit) { + pcilib_unit_t i; + + for(i = 0; ctx->units[i].name; i++) { + if (!strcasecmp(ctx->units[i].name, unit)) + return i; + } + return PCILIB_UNIT_INVALID; +} + + +int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_description_t *desc) { + if (!n) { + for (n = 0; desc[n].name; n++); + } + + if ((ctx->num_units + n + 1) > ctx->alloc_units) { + size_t size; + pcilib_unit_description_t *units; + + for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size <<= 1); + + units = (pcilib_unit_description_t*)realloc(ctx->units, size * sizeof(pcilib_unit_description_t)); + if (!units) return PCILIB_ERROR_MEMORY; + + ctx->units = units; + ctx->alloc_units = size; + + ctx->model_info.units = units; + } + + memcpy(ctx->units + ctx->num_units, desc, n * sizeof(pcilib_unit_description_t)); + memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_description_t)); + + ctx->num_units += n; + + return 0; +} |