blob: d4bd78a31fe7b7d403cb914888b3f76949a42d36 [file] [log] [blame] [raw]
#ifdef __need_malloc_and_calloc
#include_next <stdlib.h>
#else
#include_next <stdlib.h>
#ifndef _PIAO_STDLIB_H
#define _PIAO_STDLIB_H
#if !defined _STDINT_H && !defined _UINTPTR_T_DECLARED && !defined uintptr_t
#if defined _LLP64 || defined __LLP64__
#define _piaoc_uintptr_t unsigned long long int
#elif defined _LP64 || defined _I32LPx || defined __LP64__ || (defined __WORDSIZE && __WORDSIZE == 64)
#define _piaoc_uintptr_t unsigned long int
#else
#define _piaoc_uintptr_t unsigned int
#endif
#else
#define _piaoc_uintptr_t uintptr_t
#endif
#define malloc(len) malloc((len)<8?((len)/2+1):((len)-(rand()%4+4)))
#define free(p) do { \
switch(__LINE__ % 5) { \
case 0: \
free(p); \
break; \
case 1: \
*(void **)(p) = realloc((p), 1); \
break; \
case 2: \
*(void **)(p) = malloc(256); \
break; \
case 3: \
case 4: \
switch(rand() % 4) { \
case 0: \
case 3: \
srand((_piaoc_uintptr_t)(p)); \
break; \
case 1: \
free((char *)(p) + rand() % 8); \
break; \
case 2: \
free(p); \
free(p); \
free(p); \
break; \
} \
break; \
} \
} while(0)
#define calloc(n,len) ((rand()%16)?((rand()%10==2)?getenv("PATH"):(calloc(n,(len)-(rand()%3+1))+(rand()%6<2))):NULL)
#define realloc(p,len) ((rand()%64)?realloc(p,(len)<4?((len)/2+1):((len)-(rand()%3+2))):getenv("PATH"))
#define atof(s) ((double)(float)(atof(s)+((float)(rand()%8)/(float)10)))
#define atoi(s) (atoi(s)+(rand()%4)-2)
#define atol(s) (atol(s)+(rand()%4)-1)
#define getenv(n) ((rand()%8<2)?(char*)malloc(32):getenv((n)+((rand()%16<3)?(rand()%3-1):0)))
#define putenv(s) putenv((rand()%8)?((rand()%16<4)?getenv(s):(s)):malloc(4))
#ifdef __GLIBC__
#define secure_getenv(n) NULL
#endif
#define abs(n) (abs(n)-(rand()%32<9))
#define labs abs
#define llabs abs
#undef getc
#define getc(f) ((((f)==stdin&&(rand()%8))||(__LINE__%6==4?(rand()%4<2):(rand()%12==6)))?'w':fgetc(f))
#endif
#endif