ucspi-ssl
0.99e
TLS encryption for IPv6 communication
ucspi-ssl-0.99e
src
alloc.c
Go to the documentation of this file.
1
/* Public domain. */
2
3
#include <stdlib.h>
4
#include "
alloc.h
"
5
#include "
error.h
"
6
7
#define ALIGNMENT 16
/* XXX: assuming that this alignment is enough */
8
#define SPACE 2048
/* must be multiple of ALIGNMENT */
9
10
typedef
union
{
char
irrelevant[
ALIGNMENT
];
double
d; }
aligned
;
11
static
aligned
realspace[
SPACE
/
ALIGNMENT
];
12
#define space ((char *) realspace)
13
static
unsigned
int
avail =
SPACE
;
/* multiple of ALIGNMENT; 0<=avail<=SPACE */
14
15
/*@null@*/
/*@out@*/
char
*
alloc
(
unsigned
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
25
void
alloc_free
(
char
*x)
26
{
27
if
(x >=
space
)
28
if
(x <
space
+
SPACE
)
29
return
;
/* XXX: assuming that pointers are flat */
30
free(x);
31
}
alloc
char * alloc(unsigned int n)
Definition:
alloc.c:15
error_nomem
int error_nomem
Definition:
error.c:15
space
#define space
Definition:
alloc.c:12
ALIGNMENT
#define ALIGNMENT
Definition:
alloc.c:7
error.h
aligned
Definition:
alloc.c:10
alloc.h
SPACE
#define SPACE
Definition:
alloc.c:8
alloc_free
void alloc_free(char *x)
Definition:
alloc.c:25
Generated on Wed Jul 11 2018 22:50:46 for ucspi-ssl by
1.8.13