lib/xalloc: add xstrndup()

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-04-10 17:16:01 +02:00
parent 78c70e23b5
commit 2b88d3d72b
1 changed files with 15 additions and 0 deletions

View File

@ -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, ...)
{