9
0
Fork 0

svn_rev_283

add xfuncs
This commit is contained in:
Sascha Hauer 2007-07-05 18:01:39 +02:00 committed by Sascha Hauer
parent 488afcc90d
commit f0c67c6581
3 changed files with 32 additions and 25 deletions

View File

@ -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__

23
common/xfuncs.c Normal file
View File

@ -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;
}

7
include/xfuncs.h Normal file
View File

@ -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 */