From 3e27b34eb039911e9c0160e2dbc0a841fa70a570 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Sun, 23 Jan 2011 21:28:19 +0100 Subject: lib: [xalloc] don't use hardcoded return code Signed-off-by: Karel Zak --- include/xalloc.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'include/xalloc.h') diff --git a/include/xalloc.h b/include/xalloc.h index ff5432e59..fc2f886dd 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -13,13 +13,17 @@ #include #include +#ifndef XALLOC_EXIT_CODE +# define XALLOC_EXIT_CODE EXIT_FAILURE +#endif + static inline __attribute__((alloc_size(1))) void *xmalloc(const size_t size) { void *ret = malloc(size); if (!ret && size) - err(EXIT_FAILURE, "cannot allocate %zu bytes", size); + err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size); return ret; } @@ -29,7 +33,7 @@ void *xrealloc(void *ptr, const size_t size) void *ret = realloc(ptr, size); if (!ret && size) - err(EXIT_FAILURE, "cannot allocate %zu bytes", size); + err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size); return ret; } @@ -39,7 +43,7 @@ void *xcalloc(const size_t nelems, const size_t size) void *ret = calloc(nelems, size); if (!ret && size && nelems) - err(EXIT_FAILURE, "cannot allocate %zu bytes", size); + err(XALLOC_EXIT_CODE, "cannot allocate %zu bytes", size); return ret; } @@ -48,7 +52,7 @@ static inline char *xstrdup(const char *str) char *ret = strdup(str); if (!ret && str) - err(EXIT_FAILURE, "cannot duplicate string"); + err(XALLOC_EXIT_CODE, "cannot duplicate string"); return ret; } -- cgit v1.2.3-55-g7522