tinc/lib/xalloc.h
Guus Sliepen 5e0efd53e7 Add xasprintf() and xvasprintf().
These functions wrap asprintf() and vasprintf(), and check the return value. If
the function failed, tinc will exit with an error message, similar to xmalloc()
and friends.
2009-09-08 18:16:58 +02:00

29 lines
904 B
C

#include <sys/types.h>
#ifndef PARAMS
# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
#endif
/* Exit value when the requested amount of memory is not available.
The caller may set it to some other value. */
extern int xalloc_exit_failure;
/* FIXME: describe */
extern char *const xalloc_msg_memory_exhausted;
/* FIXME: describe */
extern void (*xalloc_fail_func) ();
void *xmalloc PARAMS ((size_t n)) __attribute__ ((__malloc__));
void *xmalloc_and_zero PARAMS ((size_t n)) __attribute__ ((__malloc__));
void *xcalloc PARAMS ((size_t n, size_t s));
void *xrealloc PARAMS ((void *p, size_t n)) __attribute__ ((__malloc__));
char *xstrdup PARAMS ((const char *s)) __attribute__ ((__malloc__));
extern int xasprintf(char **strp, const char *fmt, ...);
extern int xvasprintf(char **strp, const char *fmt, va_list ap);