No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / groff / src / libs / libgroff / new.cpp
blob5329f63fd0a64b587b3733aedaf7813a1443e6be
1 /* $NetBSD$ */
3 /* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2003, 2004
4 Free Software Foundation, Inc.
5 Written by James Clark (jjc@jclark.com)
7 This file is part of groff.
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING. If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
23 #include "lib.h"
25 #include <stddef.h>
26 #include <stdlib.h>
28 #include "posix.h"
29 #include "nonposix.h"
31 extern "C" const char *program_name;
33 static void ewrite(const char *s)
35 write(2, s, strlen(s));
38 void *operator new(size_t size)
40 // Avoid relying on the behaviour of malloc(0).
41 if (size == 0)
42 size++;
43 #ifdef COOKIE_BUG
44 char *p = (char *)malloc(unsigned(size + 8));
45 #else /* not COOKIE_BUG */
46 char *p = (char *)malloc(unsigned(size));
47 #endif /* not COOKIE_BUG */
48 if (p == 0) {
49 if (program_name) {
50 ewrite(program_name);
51 ewrite(": ");
53 ewrite("out of memory\n");
54 _exit(-1);
56 #ifdef COOKIE_BUG
57 ((unsigned *)p)[1] = 0;
58 return p + 8;
59 #else /* not COOKIE_BUG */
60 return p;
61 #endif /* not COOKIE_BUG */
64 void operator delete(void *p)
66 #ifdef COOKIE_BUG
67 if (p)
68 free((void *)((char *)p - 8));
69 #else
70 if (p)
71 free(p);
72 #endif /* COOKIE_BUG */