diff options
-rw-r--r-- | common/hush.c | 27 | ||||
-rw-r--r-- | common/xfuncs.c | 23 | ||||
-rw-r--r-- | include/xfuncs.h | 7 |
3 files changed, 32 insertions, 25 deletions
diff --git a/common/hush.c b/common/hush.c index e27520fb85..9911655aae 100644 --- a/common/hush.c +++ b/common/hush.c @@ -90,6 +90,7 @@ #define __U_BOOT__ #ifdef __U_BOOT__ #include <malloc.h> /* malloc, free, realloc*/ +#include <xfuncs.h> #include <linux/ctype.h> /* isalpha, isdigit */ #include <common.h> /* readline */ #include <hush.h> @@ -382,10 +383,7 @@ static void __syntax(char *file, int line) { #define syntax() __syntax(__FILE__, __LINE__) #endif -#ifdef __U_BOOT__ -static void *xmalloc(size_t size); -static void *xrealloc(void *ptr, size_t size); -#else +#ifndef __U_BOOT__ /* Index of subroutines: */ /* function prototypes for builtins */ static int builtin_cd(struct child_prog *child); @@ -3259,27 +3257,6 @@ int u_boot_hush_start(void) return 0; } -static void *xmalloc(size_t size) -{ - void *p = NULL; - - if (!(p = malloc(size))) { - printf("ERROR : memory not allocated\n"); - for(;;); - } - return p; -} - -static void *xrealloc(void *ptr, size_t size) -{ - void *p = NULL; - - if (!(p = realloc(ptr, size))) { - printf("ERROR : memory not allocated\n"); - for(;;); - } - return p; -} #endif /* __U_BOOT__ */ #ifndef __U_BOOT__ diff --git a/common/xfuncs.c b/common/xfuncs.c new file mode 100644 index 0000000000..0fc2fcb69e --- /dev/null +++ b/common/xfuncs.c @@ -0,0 +1,23 @@ + +#include <common.h> +#include <malloc.h> + +void *xmalloc(size_t size) +{ + void *p = NULL; + + if (!(p = malloc(size))) + panic("ERROR: out of memory\n"); + + return p; +} + +void *xrealloc(void *ptr, size_t size) +{ + void *p = NULL; + + if (!(p = realloc(ptr, size))) + panic("ERROR: out of memory\n"); + + return p; +} diff --git a/include/xfuncs.h b/include/xfuncs.h new file mode 100644 index 0000000000..fdb90afac9 --- /dev/null +++ b/include/xfuncs.h @@ -0,0 +1,7 @@ +#ifndef __XFUNCS_H +#define __XFUNCS_H + +void *xmalloc(size_t size); +void *xrealloc(void *ptr, size_t size); + +#endif /* __XFUNCS_H */ |