From ecc264bc39537486109c7bb80c937b5931326200 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 24 Nov 2010 16:39:15 +0100 Subject: lib: [xalloc] add xstrdup() Signed-off-by: Karel Zak --- include/xalloc.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/xalloc.h') diff --git a/include/xalloc.h b/include/xalloc.h index 2a8c78bc0..ff5432e59 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -43,4 +43,13 @@ void *xcalloc(const size_t nelems, const size_t size) return ret; } +static inline char *xstrdup(const char *str) +{ + char *ret = strdup(str); + + if (!ret && str) + err(EXIT_FAILURE, "cannot duplicate string"); + return ret; +} + #endif -- cgit v1.2.3-55-g7522