1 /* xmalloc.c -- malloc with out of memory checking
2 Copyright (C) 1990,91,92,93,94,95,96,97 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 #include <sys/types.h>
32 #if STDC_HEADERS || _LIBC
34 static VOID
*fixup_null_alloc
__P ((size_t n
));
35 VOID
*xmalloc
__P ((size_t n
));
36 VOID
*xcalloc
__P ((size_t n
, size_t s
));
37 VOID
*xrealloc
__P ((VOID
*p
, size_t n
));
49 # define _(str) gettext (str)
53 #define EXIT_FAILURE 4
56 /* Exit value when the requested amount of memory is not available.
57 The caller may set it to some other value. */
58 int xmalloc_exit_failure
= EXIT_FAILURE
;
68 p
= malloc ((size_t) 1);
70 error (xmalloc_exit_failure
, 0, _("memory exhausted"));
74 /* Allocate N bytes of memory dynamically, with error checking. */
84 p
= fixup_null_alloc (n
);
88 /* Allocate memory for N elements of S bytes, with error checking. */
98 p
= fixup_null_alloc (n
);
102 /* Change the size of an allocated block of memory P to N bytes,
104 If P is NULL, run xmalloc. */
115 p
= fixup_null_alloc (n
);