s/qmail
3.3.23
Next generation secure email transport
sqmail-3.3.23
src
alloc.c
Go to the documentation of this file.
1
#include <stdlib.h>
2
#include <stdint.h>
3
#include "
alloc.h
"
4
#include "
error.h
"
5
extern
void
*
malloc
();
6
extern
void
free
();
7
8
#define ALIGNMENT 16
/* XXX: assuming that this alignment is enough */
9
#define SPACE 4096
/* must be multiple of ALIGNMENT */
10
11
typedef
union
{
char
irrelevant[
ALIGNMENT
];
double
d
; }
aligned
;
12
static
aligned
realspace[
SPACE
/
ALIGNMENT
];
13
#define space ((char *) realspace)
14
static
unsigned
int
avail =
SPACE
;
/* multiple of ALIGNMENT; 0<=avail<=SPACE */
15
16
/*@null@*/
/*@out@*/
char
*
alloc
(
unsigned
int
n
)
17
{
18
char
*
x
;
19
n =
ALIGNMENT
+ n - (n & (
ALIGNMENT
- 1));
/* XXX: could overflow */
20
if
(n <= avail) { avail -=
n
;
return
space
+ avail; }
21
x =
malloc
(n);
22
if
(!x)
errno
=
error_nomem
;
23
return
x
;
24
}
25
26
void
alloc_free
(
char
*
x
)
27
{
28
if
(x >=
space
)
29
if
(x <
space
+
SPACE
)
30
return
;
/* XXX: assuming that pointers are flat */
31
free
(x);
32
}
alloc
char * alloc(unsigned int n)
Definition:
alloc.c:16
error_nomem
int error_nomem
Definition:
error.c:13
space
#define space
Definition:
alloc.c:13
ALIGNMENT
#define ALIGNMENT
Definition:
alloc.c:8
error.h
d
struct del * d[CHANNELS]
Definition:
qmail-send.c:716
aligned
Definition:
alloc.c:11
errno
int errno
free
void free()
alloc.h
x
unsigned x
Definition:
matchup.c:36
SPACE
#define SPACE
Definition:
alloc.c:9
n
unsigned n
Definition:
matchup.c:36
alloc_free
void alloc_free(char *x)
Definition:
alloc.c:26
malloc
void * malloc()
Generated on Sat Jan 12 2019 23:42:27 for s/qmail by
1.8.13