2 xalloc.h -- malloc and related fuctions with out of memory checking
3 Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
4 Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc., Foundation,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
20 #ifndef __TINC_XALLOC_H__
21 #define __TINC_XALLOC_H__
23 static inline void *xmalloc(size_t n
) __attribute__ ((__malloc__
));
24 static inline void *xmalloc(size_t n
) {
31 static inline void *xzalloc(size_t n
) __attribute__ ((__malloc__
));
32 static inline void *xzalloc(size_t n
) {
33 void *p
= calloc(1, n
);
39 static inline void *xrealloc(void *p
, size_t n
) {
46 static inline char *xstrdup(const char *s
) __attribute__ ((__malloc__
));
47 static inline char *xstrdup(const char *s
) {
54 static inline int xvasprintf(char **strp
, const char *fmt
, va_list ap
) {
57 int result
= vsnprintf(buf
, sizeof buf
, fmt
, ap
);
62 int result
= vasprintf(strp
, fmt
, ap
);
69 static inline int xasprintf(char **strp
, const char *fmt
, ...) __attribute__ ((__format__(printf
, 2, 3)));
70 static inline int xasprintf(char **strp
, const char *fmt
, ...) {
73 int result
= xvasprintf(strp
, fmt
, ap
);