From d367918916baf9290816aa8657cc78878b68c1ef Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 22 Nov 2014 12:10:37 +0100 Subject: Starting on some rework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/macros.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/libmdsserver/macros.h') diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index 79d427f..e7cfad5 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -37,6 +37,19 @@ */ +/** + * Wrapper around `asprintf` that makes sure that first + * argument gets set to `NULL` on error and that zero is + * returned on success rather than the number of printed + * characters + * + * @param VAR:char** The output parameter for the string + * @param ...:const char*, ... The format string and arguments + * @return :int Zero on success, -1 on error + */ +#define xasprintf(VAR, ...) \ + (asprintf(&(VAR), __VA_ARGS__) < 0 ? (VAR = NULL, -1) : 0) + /** * Wrapper for `snprintf` that allows you to forget about the buffer size * -- cgit v1.2.3-70-g09d2