Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* xmalloc.c - get memory or bust |
01170860 RP |
2 | |
3 | Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc. | |
6efd877d | 4 | |
a39116f1 | 5 | This file is part of GAS, the GNU Assembler. |
6efd877d | 6 | |
a39116f1 RP |
7 | GAS is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
6efd877d | 11 | |
a39116f1 RP |
12 | GAS is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
6efd877d | 16 | |
a39116f1 RP |
17 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 | 20 | |
fecd2382 | 21 | /* |
a39116f1 RP |
22 | NAME |
23 | xmalloc() - get memory or bust | |
24 | INDEX | |
25 | xmalloc() uses malloc() | |
6efd877d | 26 | |
a39116f1 RP |
27 | SYNOPSIS |
28 | char * my_memory; | |
6efd877d | 29 | |
a39116f1 | 30 | my_memory = xmalloc(42); / * my_memory gets address of 42 chars * / |
6efd877d | 31 | |
a39116f1 | 32 | DESCRIPTION |
6efd877d | 33 | |
a39116f1 RP |
34 | Use xmalloc() as an "error-free" malloc(). It does almost the same job. |
35 | When it cannot honour your request for memory it BOMBS your program | |
36 | with a "virtual memory exceeded" message. Malloc() returns NULL and | |
37 | does not bomb your program. | |
6efd877d | 38 | |
a39116f1 RP |
39 | SEE ALSO |
40 | malloc() | |
6efd877d | 41 | |
a39116f1 | 42 | */ |
7f2cb270 KR |
43 | |
44 | #include "as.h" | |
fecd2382 RP |
45 | |
46 | #define error as_fatal | |
47 | ||
6efd877d KR |
48 | char * |
49 | xmalloc (n) | |
a938b1d6 | 50 | unsigned long n; |
fecd2382 | 51 | { |
6efd877d | 52 | char *retval; |
6efd877d | 53 | |
a938b1d6 | 54 | retval = malloc (n); |
7f2cb270 KR |
55 | if (retval == NULL) |
56 | error ("virtual memory exceeded"); | |
6efd877d | 57 | return (retval); |
fecd2382 RP |
58 | } |
59 | ||
7f2cb270 KR |
60 | char * |
61 | xrealloc (ptr, n) | |
62 | register char *ptr; | |
a938b1d6 | 63 | unsigned long n; |
7f2cb270 | 64 | { |
a938b1d6 | 65 | ptr = realloc (ptr, n); |
7f2cb270 KR |
66 | if (ptr == 0) |
67 | error ("virtual memory exceeded"); | |
68 | return (ptr); | |
69 | } | |
8b228fe9 | 70 | /* end of xmalloc.c */ |