]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - db/malloc.c
xfsprogs: convert to SPDX license tags
[thirdparty/xfsprogs-dev.git] / db / malloc.c
CommitLineData
959ef981 1// SPDX-License-Identifier: GPL-2.0
2bd0ea18 2/*
da23017d
NS
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
2bd0ea18
NS
5 */
6
6b803e5a 7#include "libxfs.h"
2bd0ea18
NS
8#include "init.h"
9#include "malloc.h"
10#include "output.h"
11
12static void
13badmalloc(void)
14{
9ee7055c 15 dbprintf(_("%s: out of memory\n"), progname);
2bd0ea18
NS
16 exit(4);
17}
18
19void *
20xcalloc(
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
34void
35xfree(
36 void *ptr)
37{
38 free(ptr);
39}
40
41void *
42xmalloc(
43 size_t size)
44{
45 void *ptr;
46
738e3899 47 ptr = valloc(size);
2bd0ea18
NS
48 if (ptr)
49 return ptr;
50 badmalloc();
51 /* NOTREACHED */
52 return NULL;
53}
54
55void *
56xrealloc(
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
68char *
69xstrdup(
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}