1 /*
2  * alloc.h -- Useful allocation function/defintions
3  *
4  * Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can either send email to this
18  * program's maintainer or write to: The Free Software Foundation,
19  * Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
20  *
21  */
22 #ifndef ALLOC_H
23 #define ALLOC_H
24 
25 #if HAVE_CONFIG_H
26 #  include "config.h"
27 #endif /* HAVE_CONFIG_H */
28 
29 #include "common.h"
30 
31 #if !STDC_HEADERS
32 extern void free (void*);
33 #endif /* STDC_HEADERS */
34 
35 extern void set_alloc_limit (size_t size);
36 extern size_t get_alloc_limit();
37 extern void alloc_limit_assert (char *fn_name, size_t size);
38 extern void* checked_xmalloc (size_t size);
39 extern void* xmalloc (size_t size);
40 extern void* checked_xcalloc (size_t num, size_t size);
41 extern void* xcalloc (size_t num, size_t size);
42 
43 #define XMALLOC(_type,_num)			                \
44         ((_type*)xmalloc((_num)*sizeof(_type)))
45 #define XCALLOC(_type,_num) 				        \
46         ((_type*)xcalloc((_num), sizeof (_type)))
47 #define CHECKED_XMALLOC(_type,_num) 			        \
48         ((_type*)checked_xmalloc((_num)*sizeof(_type)))
49 #define CHECKED_XCALLOC(_type,_num) 			        \
50         ((_type*)checked_xcalloc((_num),sizeof(_type)))
51 #define XFREE(_ptr)						\
52 	do { if (_ptr) { free (_ptr); _ptr = 0; } } while (0)
53 
54 #endif /* ALLOC_H */
55