Sync-to-go: update copyright for 2015
[s-roff.git] / src / lib-roff / new.cpp
blobb463e192a9b8ae6ca2d7c5c80cc69765b00e71b4
1 /*@ FIXME please replace these damn allocators; especially for POD data!
2 * Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2001, 2003, 2004
5 * Free Software Foundation, Inc.
6 * Written by James Clark (jjc@jclark.com)
8 * This is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2, or (at your option) any later
11 * version.
13 * This is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with groff; see the file COPYING. If not, write to the Free Software
20 * Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "config.h"
24 #include "lib.h"
26 #include <stddef.h>
27 #include <stdlib.h>
29 #include "nonposix.h"
30 #include "posix.h"
32 extern "C" const char *program_name; // FIXME
34 static void ewrite(const char *s)
36 write(2, s, strlen(s));
39 void *operator new(size_t size)
41 // Avoid relying on the behaviour of malloc(0).
42 if (size == 0)
43 size++;
44 #ifdef COOKIE_BUG
45 char *p = (char *)malloc(unsigned(size + 8));
46 #else /* not COOKIE_BUG */
47 char *p = (char *)malloc(unsigned(size));
48 #endif /* not COOKIE_BUG */
49 if (p == 0) {
50 if (program_name) {
51 ewrite(program_name);
52 ewrite(": ");
54 ewrite("out of memory\n");
55 _exit(-1);
57 #ifdef COOKIE_BUG
58 ((unsigned *)p)[1] = 0;
59 return p + 8;
60 #else /* not COOKIE_BUG */
61 return p;
62 #endif /* not COOKIE_BUG */
65 void operator delete(void *p)
67 #ifdef COOKIE_BUG
68 if (p)
69 free((void *)((char *)p - 8));
70 #else
71 if (p)
72 free(p);
73 #endif /* COOKIE_BUG */
76 // s-it2-mode