summaryrefslogtreecommitdiff
path: root/src/aplwc_internal.h
blob: ccf600f019c13e78bc1c5b11ebdc6d462f14239e (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef APLWC_INTERNAL_H
#define APLWC_INTERNAL_H

#include <aplwc.h>

#define UNUSED_PARAMETER(arg) ((void)arg)

#define RETURN_ERROR(aplwc, rc, msg) do{ \
	Aplwc *_p = (aplwc);      \
	AplwcRc _r = APLWC_##rc;  \
	if(_p) _p->last_error = _r; \
	return _r;                \
	}while(0)

#define NELEM(x) (sizeof(x)/sizeof(x[0]))

#include <stdalign.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct Memory Memory;

struct Memory {
	uint8_t *data;
	size_t size;
	size_t offset;
};

struct Aplwc {
	AplwcRc last_error;
	char last_error_msg[64];
	Memory memory;
};

/* errors.c */
const char *rc_to_string(AplwcRc);

/* memory.c */
Memory memory_init(uint8_t *, size_t);
Aplwc *memory_alloc_aplwc(Memory *);
void memory_free_aplwc(Memory *, Aplwc *);

#endif /* APLWC_INTERNAL_H */