home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / compat / stdlib / xrealloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-10  |  559 b   |  27 lines

  1. /* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  3. #include <stdlib.h>
  4. #include <io.h>
  5. #include <unistd.h>
  6.  
  7. static char msg[] = "Fatal: xrealloc would have returned NULL\r\n";
  8.  
  9. void * xrealloc(void *ptr, size_t _sz);
  10. void *
  11. xrealloc(void *ptr, size_t _sz)
  12. {
  13.   void *rv;
  14.  
  15.   if (ptr == 0)
  16.     rv = malloc(_sz?_sz:1);
  17.   else
  18.     rv = realloc(ptr, _sz?_sz:1);
  19.  
  20.   if (rv == 0)
  21.   {
  22.     _write(STDERR_FILENO, msg, sizeof(msg)-1);
  23.     _exit(1);
  24.   }
  25.   return rv;
  26. }
  27.