]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/malloc.c
xfsprogs: convert to SPDX license tags
[thirdparty/xfsprogs-dev.git] / db / malloc.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "init.h"
9 #include "malloc.h"
10 #include "output.h"
11
12 static void
13 badmalloc(void)
14 {
15 dbprintf(_("%s: out of memory\n"), progname);
16 exit(4);
17 }
18
19 void *
20 xcalloc(
21 size_t nelem,
22 size_t elsize)
23 {
24 void *ptr;
25
26 ptr = calloc(nelem, elsize);
27 if (ptr)
28 return ptr;
29 badmalloc();
30 /* NOTREACHED */
31 return NULL;
32 }
33
34 void
35 xfree(
36 void *ptr)
37 {
38 free(ptr);
39 }
40
41 void *
42 xmalloc(
43 size_t size)
44 {
45 void *ptr;
46
47 ptr = valloc(size);
48 if (ptr)
49 return ptr;
50 badmalloc();
51 /* NOTREACHED */
52 return NULL;
53 }
54
55 void *
56 xrealloc(
57 void *ptr,
58 size_t size)
59 {
60 ptr = realloc(ptr, size);
61 if (ptr || !size)
62 return ptr;
63 badmalloc();
64 /* NOTREACHED */
65 return NULL;
66 }
67
68 char *
69 xstrdup(
70 const char *s1)
71 {
72 char *s;
73
74 s = strdup(s1);
75 if (s)
76 return s;
77 badmalloc();
78 /* NOTREACHED */
79 return NULL;
80 }