import.c: Never print more than 60 seconds
[nagios-reports-module.git] / mm.c
blob54736c6de63ede01bfe7b8a3bd11f699959fac8e
1 #include <stdlib.h>
2 #include <unistd.h>
3 #include "mm.h"
5 struct arena {
6 void *ptr;
7 size_t size;
8 struct arena *next;
9 };
11 static struct arena *arena_head, *arena_tail;
13 void *cget_arena(size_t size, size_t nmemb)
15 struct arena *a;
17 if (!size || !nmemb)
18 return NULL;
20 a = calloc(sizeof(*a), 1);
21 if (!a)
22 return NULL;
24 a->size = size * nmemb;
25 a->ptr = calloc(size, nmemb);
26 if (!a->ptr) {
27 free(a);
28 return NULL;
31 if (arena_head) {
32 arena_tail->next = a;
33 arena_tail = a;
35 else {
36 arena_head = arena_tail = a;
39 return a->ptr;
42 void *mget_arena(size_t size)
44 return cget_arena(size, 1);
47 void release_arenas(void)
49 struct arena *a;
51 a = arena_head;
52 while (a) {
53 struct arena *next;
55 next = a->next;
56 free(a->ptr);
57 free(a);
58 a = next;
60 arena_head = arena_tail = NULL;