2 * Copyright 2004-2005 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 void malloc_fail(void) __NORETURN
;
30 #define xnew(type, n) (type *)xmalloc(sizeof(type) * (n))
31 #define xnew0(type, n) (type *)xmalloc0(sizeof(type) * (n))
32 #define xrenew(type, mem, n) (type *)xrealloc(mem, sizeof(type) * (n))
34 static inline void * __MALLOC
xmalloc(size_t size
)
36 void *ptr
= malloc(size
);
38 if (unlikely(ptr
== NULL
))
43 static inline void * __MALLOC
xmalloc0(size_t size
)
45 void *ptr
= calloc(1, size
);
47 if (unlikely(ptr
== NULL
))
52 static inline void * __MALLOC
xrealloc(void *ptr
, size_t size
)
54 ptr
= realloc(ptr
, size
);
55 if (unlikely(ptr
== NULL
))
60 static inline char * __MALLOC
xstrdup(const char *str
)
62 char *s
= strdup(str
);
64 if (unlikely(s
== NULL
))
69 char * __MALLOC
xstrndup(const char *str
, size_t n
);
71 static inline void free_str_array(char **array
)
77 for (i
= 0; array
[i
]; i
++)