home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DIFFPT.ZIP / HREALLOC.C < prev    next >
C/C++ Source or Header  |  1991-07-01  |  629b  |  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.