]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2bd0ea18 NS |
17 | */ |
18 | ||
6b803e5a | 19 | #include "libxfs.h" |
2bd0ea18 NS |
20 | #include "init.h" |
21 | #include "malloc.h" | |
22 | #include "output.h" | |
23 | ||
24 | static void | |
25 | badmalloc(void) | |
26 | { | |
9ee7055c | 27 | dbprintf(_("%s: out of memory\n"), progname); |
2bd0ea18 NS |
28 | exit(4); |
29 | } | |
30 | ||
31 | void * | |
32 | xcalloc( | |
33 | size_t nelem, | |
34 | size_t elsize) | |
35 | { | |
36 | void *ptr; | |
37 | ||
38 | ptr = calloc(nelem, elsize); | |
39 | if (ptr) | |
40 | return ptr; | |
41 | badmalloc(); | |
42 | /* NOTREACHED */ | |
43 | return NULL; | |
44 | } | |
45 | ||
46 | void | |
47 | xfree( | |
48 | void *ptr) | |
49 | { | |
50 | free(ptr); | |
51 | } | |
52 | ||
53 | void * | |
54 | xmalloc( | |
55 | size_t size) | |
56 | { | |
57 | void *ptr; | |
58 | ||
738e3899 | 59 | ptr = valloc(size); |
2bd0ea18 NS |
60 | if (ptr) |
61 | return ptr; | |
62 | badmalloc(); | |
63 | /* NOTREACHED */ | |
64 | return NULL; | |
65 | } | |
66 | ||
67 | void * | |
68 | xrealloc( | |
69 | void *ptr, | |
70 | size_t size) | |
71 | { | |
72 | ptr = realloc(ptr, size); | |
73 | if (ptr || !size) | |
74 | return ptr; | |
75 | badmalloc(); | |
76 | /* NOTREACHED */ | |
77 | return NULL; | |
78 | } | |
79 | ||
80 | char * | |
81 | xstrdup( | |
82 | const char *s1) | |
83 | { | |
84 | char *s; | |
85 | ||
86 | s = strdup(s1); | |
87 | if (s) | |
88 | return s; | |
89 | badmalloc(); | |
90 | /* NOTREACHED */ | |
91 | return NULL; | |
92 | } |