]> git.ipfire.org Git - thirdparty/mdadm.git/blob - xmalloc.c
8d42a7c4ef4ebb57a7a2c71cd9cf887f9db98a15
[thirdparty/mdadm.git] / xmalloc.c
1 /* mdadm - manage Linux "md" devices aka RAID arrays.
2 *
3 * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * Author: Neil Brown
21 * Email: <neilb@suse.de>
22 */
23
24 #include "mdadm.h"
25 /*#include <sys/socket.h>
26 #include <sys/utsname.h>
27 #include <sys/wait.h>
28 #include <sys/un.h>
29 #include <ctype.h>
30 #include <dirent.h>
31 #include <signal.h>
32 */
33
34 void *xmalloc(size_t len)
35 {
36 void *rv = malloc(len);
37 char *msg;
38 if (rv)
39 return rv;
40 msg = Name ": memory allocation failure - aborting\n";
41 exit(4+!!write(2, msg, strlen(msg)));
42 }
43
44 void *xrealloc(void *ptr, size_t len)
45 {
46 void *rv = realloc(ptr, len);
47 char *msg;
48 if (rv)
49 return rv;
50 msg = Name ": memory allocation failure - aborting\n";
51 exit(4+!!write(2, msg, strlen(msg)));
52 }
53
54 void *xcalloc(size_t num, size_t size)
55 {
56 void *rv = calloc(num, size);
57 char *msg;
58 if (rv)
59 return rv;
60 msg = Name ": memory allocation failure - aborting\n";
61 exit(4+!!write(2, msg, strlen(msg)));
62 }
63
64 char *xstrdup(const char *str)
65 {
66 char *rv = strdup(str);
67 char *msg;
68 if (rv)
69 return rv;
70 msg = Name ": memory allocation failure - aborting\n";
71 exit(4+!!write(2, msg, strlen(msg)));
72 }