]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/malloc.c
apply gettext translation to more strings
[thirdparty/xfsprogs-dev.git] / db / malloc.c
1 /*
2 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18
19 #include <xfs/libxfs.h>
20 #include "init.h"
21 #include "malloc.h"
22 #include "output.h"
23
24 static void
25 badmalloc(void)
26 {
27 dbprintf(_("%s: out of memory\n"), progname);
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
59 ptr = valloc(size);
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 }