154359Sroberto/*
254359Sroberto * Define malloc and friends.
354359Sroberto */
4285612Sdelphij#ifndef NTP_MALLOC_H
5285612Sdelphij#define NTP_MALLOC_H
654359Sroberto
754359Sroberto#ifdef HAVE_STDLIB_H
854359Sroberto# include <stdlib.h>
9285612Sdelphij#else
1054359Sroberto# ifdef HAVE_MALLOC_H
1154359Sroberto#  include <malloc.h>
1254359Sroberto# endif
13285612Sdelphij#endif
1454359Sroberto
15285612Sdelphij/*
16285612Sdelphij * Deal with platform differences declaring alloca()
17285612Sdelphij * This comes nearly verbatim from:
18285612Sdelphij *
19285612Sdelphij * http://www.gnu.org/software/autoconf/manual/autoconf.html#Particular-Functions
20285612Sdelphij *
21285612Sdelphij * The only modifications were to remove C++ support and guard against
22285612Sdelphij * redefining alloca.
23285612Sdelphij */
24285612Sdelphij#ifdef HAVE_ALLOCA_H
25285612Sdelphij# include <alloca.h>
26285612Sdelphij#elif defined __GNUC__
27285612Sdelphij# ifndef alloca
28285612Sdelphij#  define alloca __builtin_alloca
29285612Sdelphij# endif
30285612Sdelphij#elif defined _AIX
31285612Sdelphij# ifndef alloca
32285612Sdelphij#  define alloca __alloca
33285612Sdelphij# endif
34285612Sdelphij#elif defined _MSC_VER
35285612Sdelphij# include <malloc.h>
36285612Sdelphij# ifndef alloca
37285612Sdelphij#  define alloca _alloca
38285612Sdelphij# endif
39285612Sdelphij#else
40285612Sdelphij# include <stddef.h>
41285612Sdelphijvoid * alloca(size_t);
42285612Sdelphij#endif
43285612Sdelphij
44285612Sdelphij#ifdef EREALLOC_IMPL
45285612Sdelphij# define EREALLOC_CALLSITE	/* preserve __FILE__ and __LINE__ */
46285612Sdelphij#else
47285612Sdelphij# define EREALLOC_IMPL(ptr, newsz, filenm, loc) \
48285612Sdelphij	 realloc(ptr, (newsz))
49285612Sdelphij#endif
50285612Sdelphij
51285612Sdelphij#ifdef HAVE_STRINGS_H
52285612Sdelphij# include <strings.h>
53285612Sdelphij# define zero_mem(p, s)		bzero(p, s)
54285612Sdelphij#endif
55285612Sdelphij
56285612Sdelphij#ifndef zero_mem
57285612Sdelphij# define zero_mem(p, s)		memset(p, 0, s)
58285612Sdelphij#endif
59285612Sdelphij#define ZERO(var)		zero_mem(&(var), sizeof(var))
60285612Sdelphij
61285612Sdelphij#endif	/* NTP_MALLOC_H */
62