home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rcs567s.zip / diff16 / hrealloc.c < prev    next >
C/C++ Source or Header  |  1991-09-18  |  598b  |  33 lines

  1. #include "diff.h"
  2.  
  3. /* #include <sys/types.h>
  4. #include <malloc.h> */
  5.  
  6. /* by Thorsten Ohl */
  7.  
  8. void huge *hrealloc(void huge *ptr, long new_size, long old_size)
  9. {
  10.   void huge *value = halloc(new_size, (size_t) 1);
  11.  
  12.   if ( !value )
  13.     fatal("virtual memory exhausted");
  14.   else
  15.   {
  16.     char huge *dest = value;
  17.     char huge *src = ptr;
  18.  
  19.     while ( old_size > 0L )
  20.     {
  21.       unsigned int bytes = (unsigned int) min(0x8000L, old_size);
  22.       memcpy(dest, src, bytes);
  23.       old_size -= (long) bytes;
  24.       dest += (long) bytes;
  25.       src += (long) bytes;
  26.     }
  27.   }
  28.  
  29.   hfree (ptr);
  30.  
  31.   return value;
  32. }
  33.