summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/xalloc.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/xalloc.h b/include/xalloc.h
index 1f29621ef..6342793e4 100644
--- a/include/xalloc.h
+++ b/include/xalloc.h
@@ -63,6 +63,21 @@ static inline char *xstrdup(const char *str)
return ret;
}
+static inline char *xstrndup(const char *str, size_t size)
+{
+ char *ret;
+
+ if (!str)
+ return NULL;
+
+ ret = strndup(str, size);
+
+ if (!ret)
+ err(XALLOC_EXIT_CODE, "cannot duplicate string");
+ return ret;
+}
+
+
static inline int __attribute__ ((__format__(printf, 2, 3)))
xasprintf(char **strp, const char *fmt, ...)
{