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