Add basic support for mini2440 board to barebox.
[barebox-mini2440.git] / lib / xfuncs.c
blob01a64cf5eb480bd13900cfcef82bff508cb8464f
1 /*
2 * xfuncs.c - safe malloc funcions
4 * based on busybox
6 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
8 * See file CREDITS for list of people who contributed to this
9 * project.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <common.h>
26 #include <malloc.h>
27 #include <module.h>
29 void *xmalloc(size_t size)
31 void *p = NULL;
33 if (!(p = malloc(size)))
34 panic("ERROR: out of memory\n");
36 debug("xmalloc %p (size %d)\n", p, size);
38 return p;
40 EXPORT_SYMBOL(xmalloc);
42 void *xrealloc(void *ptr, size_t size)
44 void *p = NULL;
46 if (!(p = realloc(ptr, size)))
47 panic("ERROR: out of memory\n");
49 debug("xrealloc %p -> %p (size %d)\n", ptr, p, size);
51 return p;
53 EXPORT_SYMBOL(xrealloc);
55 void *xzalloc(size_t size)
57 void *ptr = xmalloc(size);
58 memset(ptr, 0, size);
59 return ptr;
61 EXPORT_SYMBOL(xzalloc);
63 char *xstrdup(const char *s)
65 char *p = strdup(s);
67 if (!p)
68 panic("ERROR: out of memory\n");
69 return p;
71 EXPORT_SYMBOL(xstrdup);