aboutsummaryrefslogtreecommitdiffstats
path: root/src/zsave.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/zsave.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/zsave.c')
-rw-r--r--src/zsave.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/zsave.c b/src/zsave.c
new file mode 100644
index 0000000..b312307
--- /dev/null
+++ b/src/zsave.c
@@ -0,0 +1,20 @@
+/* See LICENSE file for copyright and license details. */
+#include "internals"
+
+#include <string.h>
+
+
+size_t
+zsave(z_t a, void *buffer)
+{
+ if (buffer) {
+ char *buf = buffer;
+ *((int *)buf) = a->sign, buf += sizeof(int);
+ *((size_t *)buf) = a->used, buf += sizeof(size_t);
+ *((size_t *)buf) = a->alloced, buf += sizeof(size_t);
+ if (a->sign) {
+ memcpy(buf, a->chars, a->used * sizeof(*(a->chars)));
+ }
+ }
+ return sizeof(z_t) - sizeof(a->chars) + (a->sign ? a->used * sizeof(*(a->chars)) : 0);
+}