summaryrefslogtreecommitdiffstats
path: root/alloc.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
committermanuel <manuel@mausz.at>2013-02-04 00:08:53 +0100
commit69aec538b456402170dc723af417ba5c05389c32 (patch)
treee6f34c543f17c6392447ea337b2e2868212424d1 /alloc.c
downloadqmail-69aec538b456402170dc723af417ba5c05389c32.tar.gz
qmail-69aec538b456402170dc723af417ba5c05389c32.tar.bz2
qmail-69aec538b456402170dc723af417ba5c05389c32.zip
qmail 1.03 import
Diffstat (limited to 'alloc.c')
-rw-r--r--alloc.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/alloc.c b/alloc.c
new file mode 100644
index 0000000..c661453
--- /dev/null
+++ b/alloc.c
@@ -0,0 +1,32 @@
1#include "alloc.h"
2#include "error.h"
3extern char *malloc();
4extern void free();
5
6#define ALIGNMENT 16 /* XXX: assuming that this alignment is enough */
7#define SPACE 4096 /* must be multiple of ALIGNMENT */
8
9typedef union { char irrelevant[ALIGNMENT]; double d; } aligned;
10static aligned realspace[SPACE / ALIGNMENT];
11#define space ((char *) realspace)
12static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
13
14/*@null@*//*@out@*/char *alloc(n)
15unsigned int n;
16{
17 char *x;
18 n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
19 if (n <= avail) { avail -= n; return space + avail; }
20 x = malloc(n);
21 if (!x) errno = error_nomem;
22 return x;
23}
24
25void alloc_free(x)
26char *x;
27{
28 if (x >= space)
29 if (x < space + SPACE)
30 return; /* XXX: assuming that pointers are flat */
31 free(x);
32}