From e8c1abd6e75d35e747611bcad82d0d4a6564beca Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 22 Jan 2008 14:20:22 +0000 Subject: minios: POSIX fixes Fixes some functions which are POSIX. Also make them ifndef HAVE_LIBC. Signed-off-by: Samuel Thibault --- extras/mini-os/include/xmalloc.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'extras/mini-os/include/xmalloc.h') diff --git a/extras/mini-os/include/xmalloc.h b/extras/mini-os/include/xmalloc.h index 26ae9dd012..e168a84f88 100644 --- a/extras/mini-os/include/xmalloc.h +++ b/extras/mini-os/include/xmalloc.h @@ -1,11 +1,15 @@ #ifndef __XMALLOC_H__ #define __XMALLOC_H__ +#ifdef HAVE_LIBC + +#include +#include /* Allocate space for typed object. */ -#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) +#define _xmalloc(size, align) memalign(align, size) +#define xfree(ptr) free(ptr) -/* Allocate space for array of typed objects. */ -#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) +#else #define DEFAULT_ALIGN (sizeof(unsigned long)) #define malloc(size) _xmalloc(size, DEFAULT_ALIGN) @@ -19,6 +23,8 @@ extern void xfree(const void *); extern void *_xmalloc(size_t size, size_t align); extern void *_realloc(void *ptr, size_t size); +#endif + static inline void *_xmalloc_array(size_t size, size_t align, size_t num) { /* Check for overflow. */ @@ -27,4 +33,10 @@ static inline void *_xmalloc_array(size_t size, size_t align, size_t num) return _xmalloc(size * num, align); } +/* Allocate space for typed object. */ +#define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type))) + +/* Allocate space for array of typed objects. */ +#define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num)) + #endif /* __XMALLOC_H__ */ -- cgit v1.2.3