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