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