ntp_malloc.h revision 1.2 1 1.1 kardel /* $NetBSD: ntp_malloc.h,v 1.2 2014/12/19 20:43:14 christos Exp $ */
2 1.1 kardel
3 1.1 kardel /*
4 1.1 kardel * Define malloc and friends.
5 1.1 kardel */
6 1.1 kardel #ifndef NTP_MALLOC_H
7 1.1 kardel #define NTP_MALLOC_H
8 1.1 kardel
9 1.1 kardel #ifdef HAVE_STDLIB_H
10 1.1 kardel # include <stdlib.h>
11 1.1 kardel #else
12 1.1 kardel # ifdef HAVE_MALLOC_H
13 1.1 kardel # include <malloc.h>
14 1.1 kardel # endif
15 1.1 kardel #endif
16 1.1 kardel
17 1.2 christos /*
18 1.2 christos * Deal with platform differences declaring alloca()
19 1.2 christos * This comes nearly verbatim from:
20 1.2 christos *
21 1.2 christos * http://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Functions
22 1.2 christos *
23 1.2 christos * The only modifications were to remove C++ support and guard against
24 1.2 christos * redefining alloca.
25 1.2 christos */
26 1.2 christos #ifdef HAVE_ALLOCA_H
27 1.2 christos # include <alloca.h>
28 1.2 christos #elif defined __GNUC__
29 1.2 christos # ifndef alloca
30 1.2 christos # define alloca __builtin_alloca
31 1.2 christos # endif
32 1.2 christos #elif defined _AIX
33 1.2 christos # ifndef alloca
34 1.2 christos # define alloca __alloca
35 1.2 christos # endif
36 1.2 christos #elif defined _MSC_VER
37 1.2 christos # include <malloc.h>
38 1.2 christos # ifndef alloca
39 1.2 christos # define alloca _alloca
40 1.2 christos # endif
41 1.2 christos #else
42 1.2 christos # include <stddef.h>
43 1.2 christos void * alloca(size_t);
44 1.2 christos #endif
45 1.2 christos
46 1.2 christos #ifdef EREALLOC_IMPL
47 1.2 christos # define EREALLOC_CALLSITE /* preserve __FILE__ and __LINE__ */
48 1.2 christos #else
49 1.2 christos # define EREALLOC_IMPL(ptr, newsz, filenm, loc) \
50 1.2 christos realloc(ptr, (newsz))
51 1.2 christos #endif
52 1.2 christos
53 1.2 christos #ifdef HAVE_STRINGS_H
54 1.2 christos # include <strings.h>
55 1.2 christos # define zero_mem(p, s) bzero(p, s)
56 1.2 christos #endif
57 1.2 christos
58 1.2 christos #ifndef zero_mem
59 1.2 christos # define zero_mem(p, s) memset(p, 0, s)
60 1.2 christos #endif
61 1.2 christos #define ZERO(var) zero_mem(&(var), sizeof(var))
62 1.2 christos
63 1.1 kardel #endif /* NTP_MALLOC_H */
64