diff options
author | nicolas.zilio@hotmail.fr <> | 2015-09-14 11:56:38 +0200 |
---|---|---|
committer | nicolas.zilio@hotmail.fr <> | 2015-09-14 11:56:38 +0200 |
commit | 2dfb23016c39a331bf5ed4111b630dffa330edbb (patch) | |
tree | 995c98cf6c329aaf8996bb57bb95b44198b4a984 /pcilib/unit.c | |
parent | 60c6bf9f6916b6ae2c05a499675ff54480256ece (diff) | |
download | pcitool-2dfb23016c39a331bf5ed4111b630dffa330edbb.tar.gz pcitool-2dfb23016c39a331bf5ed4111b630dffa330edbb.tar.bz2 pcitool-2dfb23016c39a331bf5ed4111b630dffa330edbb.tar.xz pcitool-2dfb23016c39a331bf5ed4111b630dffa330edbb.zip |
views working fine, units in progress
Diffstat (limited to 'pcilib/unit.c')
-rw-r--r-- | pcilib/unit.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pcilib/unit.c b/pcilib/unit.c new file mode 100644 index 0000000..a9766ed --- /dev/null +++ b/pcilib/unit.c @@ -0,0 +1,34 @@ +#include "pcilib.h" +#include "pci.h" +#include "stdio.h" +#include <string.h> +#include "error.h" +#include "unit.h" + +int pcilib_add_units(pcilib_t *ctx, size_t n, const pcilib_unit_t* units) { + + pcilib_unit_t *units2; + size_t size; + + if (!n) { + for (n = 0; units[n].name[0]; n++); + } + + if ((ctx->num_units + n + 1) > ctx->alloc_units) { + for (size = ctx->alloc_units; size < 2 * (n + ctx->num_units + 1); size<<=1); + + units2 = (pcilib_unit_t*)realloc(ctx->units, size * sizeof(pcilib_unit_t)); + if (!units2) return PCILIB_ERROR_MEMORY; + + ctx->units = units2; + ctx->alloc_units = size; + } + + memcpy(ctx->units + ctx->num_units, units, n * sizeof(pcilib_unit_t)); + memset(ctx->units + ctx->num_units + n, 0, sizeof(pcilib_unit_t)); + + ctx->num_units += n; + + return 0; +} + |