ia64/xen-unstable

view extras/mini-os/include/xmalloc.h @ 16737:8984cc0a1d80

minios: add realloc

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Signed-off-by: Tim Deegan <tim.deegan@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 15:06:30 2008 +0000 (2008-01-17)
parents 7557f0b4098c
children 5f3c236d1711
line source
1 #ifndef __XMALLOC_H__
2 #define __XMALLOC_H__
4 /* Allocate space for typed object. */
5 #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
7 /* Allocate space for array of typed objects. */
8 #define xmalloc_array(_type, _num) ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
10 #define malloc(size) _xmalloc(size, 4)
11 #define free(ptr) xfree(ptr)
12 #define realloc(ptr, size) _realloc(ptr, size)
14 /* Free any of the above. */
15 extern void xfree(const void *);
17 /* Underlying functions */
18 extern void *_xmalloc(size_t size, size_t align);
19 extern void *_realloc(void *ptr, size_t size);
21 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
22 {
23 /* Check for overflow. */
24 if (size && num > UINT_MAX / size)
25 return NULL;
26 return _xmalloc(size * num, align);
27 }
29 #endif /* __XMALLOC_H__ */