From ecc264bc39537486109c7bb80c937b5931326200 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 24 Nov 2010 16:39:15 +0100 Subject: [PATCH] lib: [xalloc] add xstrdup() Signed-off-by: Karel Zak --- include/xalloc.h | 9 +++++++++ misc-utils/wipefs.c | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/xalloc.h b/include/xalloc.h index 2a8c78bc..ff5432e5 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 diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 2f223f0c..d3033446 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -136,15 +136,6 @@ add_offset(struct wipe_desc *wp0, loff_t offset, int zap) return wp; } -static inline char * -xstrdup(const char *s) -{ - char *x = strdup(s); - if (!x) - err(EXIT_FAILURE, _("strdup failed")); - return x; -} - static struct wipe_desc * get_offset_from_probe(struct wipe_desc *wp, blkid_probe pr, int zap) { -- 2.39.5