]> git.ipfire.org Git - thirdparty/mdadm.git/blob - xmalloc.c
Show all bitmaps while examining bitmap
[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 = ": memory allocation failure - aborting\n";
41 write(2, Name, strlen(Name));
42 exit(4+!!write(2, msg, strlen(msg)));
43 }
44
45 void *xrealloc(void *ptr, size_t len)
46 {
47 void *rv = realloc(ptr, len);
48 char *msg;
49 if (rv)
50 return rv;
51 msg = ": memory allocation failure - aborting\n";
52 write(2, Name, strlen(Name));
53 exit(4+!!write(2, msg, strlen(msg)));
54 }
55
56 void *xcalloc(size_t num, size_t size)
57 {
58 void *rv = calloc(num, size);
59 char *msg;
60 if (rv)
61 return rv;
62 msg = ": memory allocation failure - aborting\n";
63 write(2, Name, strlen(Name));
64 exit(4+!!write(2, msg, strlen(msg)));
65 }
66
67 char *xstrdup(const char *str)
68 {
69 char *rv = strdup(str);
70 char *msg;
71 if (rv)
72 return rv;
73 msg = ": memory allocation failure - aborting\n";
74 write(2, Name, strlen(Name));
75 exit(4+!!write(2, msg, strlen(msg)));
76 }