From b0c1cae18066d0103a440894b5256939852021eb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Mar 2016 18:37:05 +0100 Subject: Add zsetup, zunsetup, zinit, zfree, zswap, zsave, zload, zbits, and zlsb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zload.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/zload.c (limited to 'src/zload.c') diff --git a/src/zload.c b/src/zload.c new file mode 100644 index 0000000..53fae12 --- /dev/null +++ b/src/zload.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "internals" + +#include +#include + + +size_t +zload(z_t a, const void *buffer) +{ + const char *buf = buffer; + a->sign = *((int *)buf), buf += sizeof(int); + a->used = *((size_t *)buf), buf += sizeof(size_t); + a->alloced = *((size_t *)buf), buf += sizeof(size_t); + if (a->alloced) { + a->chars = realloc(a->chars, a->alloced * sizeof(*(a->chars))); + } else { + a->chars = 0; + } + if (a->sign) { + memcpy(a->chars, buf, a->used * sizeof(*(a->chars))); + } + return sizeof(z_t) - sizeof(a->chars) + (a->sign ? a->used * sizeof(*(a->chars)) : 0); +} -- cgit v1.2.3-70-g09d2