home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdlib / realloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  382 b   |  25 lines

  1. #include <stdlib.h>
  2. #ifdef __GNUC__
  3. #include <inline/exec.h>
  4. #endif
  5.  
  6. void *realloc(void *ptr,unsigned long size)
  7. {
  8.   void *a;
  9.   unsigned long l;
  10.   if(size)
  11.     a=malloc(size);
  12.   else
  13.     a=NULL;
  14.   if(ptr!=NULL)
  15.   { if(a!=NULL)
  16.     { l=((ULONG *)ptr)[-1]-sizeof(ULONG);
  17.       l=l<size?l:size;
  18.       CopyMem(ptr,a,l);
  19.     }
  20.     if(size==0||a!=NULL)
  21.       free(ptr);
  22.   }
  23.   return a;
  24. }
  25.