]> git.neil.brown.name Git - mdadm.git/blob - xmalloc.c
Release mdadm-4.0
[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         int n;
39         if (rv)
40                 return rv;
41         msg = ": memory allocation failure - aborting\n";
42         n = write(2, Name, strlen(Name));
43         n += write(2, msg, strlen(msg));
44         exit(4+!!n);
45 }
46
47 void *xrealloc(void *ptr, size_t len)
48 {
49         void *rv = realloc(ptr, len);
50         char *msg;
51         int n;
52         if (rv)
53                 return rv;
54         msg =  ": memory allocation failure - aborting\n";
55         n = write(2, Name, strlen(Name));
56         n += write(2, msg, strlen(msg));
57         exit(4+!!n);
58 }
59
60 void *xcalloc(size_t num, size_t size)
61 {
62         void *rv = calloc(num, size);
63         char *msg;
64         int n;
65         if (rv)
66                 return rv;
67         msg =  ": memory allocation failure - aborting\n";
68         n = write(2, Name, strlen(Name));
69         n += write(2, msg, strlen(msg));
70         exit(4+!!n);
71 }
72
73 char *xstrdup(const char *str)
74 {
75         char *rv = strdup(str);
76         char *msg;
77         int n;
78         if (rv)
79                 return rv;
80         msg =  ": memory allocation failure - aborting\n";
81         n = write(2, Name, strlen(Name));
82         n += write(2, msg, strlen(msg));
83         exit(4+!!n);
84 }