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 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) {
30 static inline void *xmalloc_and_zero(size_t n) {
31 void *p = calloc(1, n);
37 static inline void *xrealloc(void *p, size_t n) {
44 static inline char *xstrdup(const char *s) {
51 static inline int xvasprintf(char **strp, const char *fmt, va_list ap) {
52 int result = vasprintf(strp, fmt, ap);
58 static inline int xasprintf(char **strp, const char *fmt, ...) {
61 int result = xvasprintf(strp, fmt, ap);