]> git.ipfire.org Git - thirdparty/mdadm.git/blame - xmalloc.c
Add failfast support.
[thirdparty/mdadm.git] / xmalloc.c
CommitLineData
1cc101f3
RB
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
34void *xmalloc(size_t len)
35{
36 void *rv = malloc(len);
37 char *msg;
27aefbdb 38 int n;
1cc101f3
RB
39 if (rv)
40 return rv;
d56dd607 41 msg = ": memory allocation failure - aborting\n";
27aefbdb
N
42 n = write(2, Name, strlen(Name));
43 n += write(2, msg, strlen(msg));
44 exit(4+!!n);
1cc101f3
RB
45}
46
47void *xrealloc(void *ptr, size_t len)
48{
49 void *rv = realloc(ptr, len);
50 char *msg;
27aefbdb 51 int n;
1cc101f3
RB
52 if (rv)
53 return rv;
d56dd607 54 msg = ": memory allocation failure - aborting\n";
27aefbdb
N
55 n = write(2, Name, strlen(Name));
56 n += write(2, msg, strlen(msg));
57 exit(4+!!n);
1cc101f3
RB
58}
59
60void *xcalloc(size_t num, size_t size)
61{
62 void *rv = calloc(num, size);
63 char *msg;
27aefbdb 64 int n;
1cc101f3
RB
65 if (rv)
66 return rv;
d56dd607 67 msg = ": memory allocation failure - aborting\n";
27aefbdb
N
68 n = write(2, Name, strlen(Name));
69 n += write(2, msg, strlen(msg));
70 exit(4+!!n);
1cc101f3
RB
71}
72
73char *xstrdup(const char *str)
74{
75 char *rv = strdup(str);
76 char *msg;
27aefbdb 77 int n;
1cc101f3
RB
78 if (rv)
79 return rv;
d56dd607 80 msg = ": memory allocation failure - aborting\n";
27aefbdb
N
81 n = write(2, Name, strlen(Name));
82 n += write(2, msg, strlen(msg));
83 exit(4+!!n);
1cc101f3 84}