home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / TEKST / GROFFSRC / SRC / LIBGROFF / NEW.CC < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-03  |  1.6 KB  |  68 lines

  1. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  2.      Written by James Clark (jjc@jclark.com)
  3.  
  4. This file is part of groff.
  5.  
  6. groff is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 2, or (at your option) any later
  9. version.
  10.  
  11. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  12. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14. for more details.
  15.  
  16. You should have received a copy of the GNU General Public License along
  17. with groff; see the file COPYING.  If not, write to the Free Software
  18. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. #include <io.h>
  21. #include <stddef.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. #include "posix.h"
  26.  
  27. extern const char *program_name;
  28.  
  29. static void ewrite(const char *s)
  30. {
  31.   write(2, s, strlen(s));
  32. }
  33.  
  34. void *operator new(size_t size)
  35. {
  36.   // Avoid relying on the behaviour of malloc(0).
  37.   if (size == 0)
  38.     size++;
  39. #ifdef COOKIE_BUG
  40.   char *p = (char *)malloc(unsigned(size + 8));
  41.   if (p != 0) {
  42.     ((unsigned *)p)[1] = 0;
  43.     return p + 8;
  44.   }
  45. #else /* not COOKIE_BUG */
  46.   char *p = (char *)malloc(unsigned(size));
  47.   if (p != 0)
  48.     return p;
  49. #endif /* not COOKIE_BUG */
  50.   if (program_name) {
  51.     ewrite(program_name);
  52.     ewrite(": ");
  53.   }
  54.   ewrite("out of memory\n");
  55.   _exit(-1);
  56. }
  57.  
  58. void operator delete(void *p)
  59. {
  60.   if (p)
  61. #ifdef COOKIE_BUG
  62.     free((void *)((char *)p - 8));
  63. #else
  64.     free(p);
  65. #endif /* COOKIE_BUG */
  66. }
  67.  
  68.