aboutsummaryrefslogtreecommitdiffstats
path: root/src/zload.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-01 18:37:05 +0100
committerMattias Andrée <maandree@kth.se>2016-03-01 18:37:05 +0100
commitb0c1cae18066d0103a440894b5256939852021eb (patch)
treeb90f419aba218eedf1cc664c7269666306e6ccaf /src/zload.c
parentAdd .gitignore (diff)
downloadlibzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.gz
libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.bz2
libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.xz
Add zsetup, zunsetup, zinit, zfree, zswap, zsave, zload, zbits, and zlsb
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zload.c')
-rw-r--r--src/zload.c24
1 files changed, 24 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+
+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);
+}