readchar fix
[vde.git] / vde-2 / utils / realloc.c
blob8395f5127efc64f615a6ee9e05b09cdfac187354
2 #include <stdlib.h>
3 #undef realloc
5 void * rpl_realloc(void *ptr, size_t size)
7 void *mem;
8 if (size <= 0){ /* For zero or less bytes, free the original memory */
9 if (ptr) free(ptr);
10 return NULL;
12 else if (!ptr) /* Allow reallocation of a NULL pointer. */
13 return malloc(size);
14 else { /* Allocate a new block, copy and free the old block. */
15 mem=malloc(size);
16 if (mem) {
17 memcpy (mem, ptr, size);
18 free(ptr);
20 /* Note that the contents of PTR are not damaged if there is
21 insufficient memory to realloc. */
22 return mem;