1 /*
2    Replacement memory allocation handling etc.
3    Copyright (C) 1999-2002, Joe Orton <joe@manyfish.co.uk>
4 
5    This library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public
7    License as published by the Free Software Foundation; either
8    version 2 of the License, or (at your option) any later version.
9 
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Library General Public License for more details.
14 
15    You should have received a copy of the GNU Library General Public
16    License along with this library; if not, write to the Free
17    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18    MA 02111-1307, USA
19 
20 */
21 
22 #ifndef NE_ALLOC_H
23 #define NE_ALLOC_H
24 
25 #ifdef WIN32
26 #include <stdlib.h>
27 #else
28 #include <sys/types.h>
29 #endif
30 
31 #include "ne_defs.h"
32 
33 BEGIN_NEON_DECLS
34 
35 /* Set callback which is called if malloc() returns NULL. */
36 void ne_oom_callback(void (*callback)(void));
37 
38 #ifndef NEON_MEMLEAK
39 /* Replacements for standard C library memory allocation functions,
40  * which never return NULL. If the C library malloc() returns NULL,
41  * neon will abort(); calling an OOM callback beforehand if one is
42  * registered.  The C library will only ever return NULL if the
43  * operating system does not use optimistic memory allocation. */
44 void *ne_malloc(size_t size);
45 void *ne_calloc(size_t size);
46 void *ne_realloc(void *ptr, size_t s);
47 char *ne_strdup(const char *s);
48 char *ne_strndup(const char *s, size_t n);
49 #define ne_free free
50 #endif
51 
52 /* Handy macro to free things: takes an lvalue, and sets to NULL
53  * afterwards. */
54 #define NE_FREE(x) do { if ((x) != NULL) ne_free((x)); (x) = NULL; } while (0)
55 
56 END_NEON_DECLS
57 
58 #endif /* NE_ALLOC_H */
59