/************************************************************* * File: lib/realloc.c * Purpose: Part of C runtime library * Author: Phil Bunce (pjb@carmel.com) * Revision History: * 970304 Start of revision history */ /* This is rather an unsophisticated implementation because it copies * the data to a new area and frees the old one. It would be better to * release the unused portion of the memory block without performing * a copy. */ #include void *realloc(void *ptr,size_t size) { char *p; unsigned int sz; p = malloc(size); if (!p) return(p); sz = allocsize(ptr); memcpy(p,ptr,(sz>size)?size:sz); free(ptr); return(p); }