aboutsummaryrefslogtreecommitdiffstats
path: root/src/zload.c
blob: e03d9113bf84558f58b4ef41e410ed6da16595f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 (!zzero(a)) {
		memcpy(a->chars, buf, a->used * sizeof(*(a->chars)));
	}
	return sizeof(z_t) - sizeof(a->chars) + (zzero(a) ? 0 : a->used * sizeof(*(a->chars)));
}