From: Karel Zak Date: Wed, 24 Nov 2010 15:39:15 +0000 (+0100) Subject: lib: [xalloc] add xstrdup() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecc264bc39537486109c7bb80c937b5931326200;p=util-linux lib: [xalloc] add xstrdup() Signed-off-by: Karel Zak --- 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) {