diff options
author | Karel Zak | 2011-01-23 21:28:19 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-23 21:28:19 +0100 |
commit | 3e27b34eb039911e9c0160e2dbc0a841fa70a570 (patch) | |
tree | bb01e4fb853ff03f76ef3fd1d75af0342e9cc579 /include/xalloc.h | |
parent | libmount: cleanup API, remove typedef (diff) | |
download | kernel-qcow2-util-linux-3e27b34eb039911e9c0160e2dbc0a841fa70a570.tar.gz kernel-qcow2-util-linux-3e27b34eb039911e9c0160e2dbc0a841fa70a570.tar.xz kernel-qcow2-util-linux-3e27b34eb039911e9c0160e2dbc0a841fa70a570.zip |
lib: [xalloc] don't use hardcoded return code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/xalloc.h')
-rw-r--r-- | include/xalloc.h | 12 |
1 files changed, 8 insertions, 4 deletions
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 <stdlib.h> #include <err.h> +#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; } |