From 6310769c3c022300dfd9903ff822ac43fba6446f Mon Sep 17 00:00:00 2001 From: Emil Renner Berthing Date: Fri, 19 Sep 2014 19:43:10 +0200 Subject: [PATCH] string.h: add strndupa --- include/string.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/string.h b/include/string.h index ff9badb9..5c75b2f9 100644 --- a/include/string.h +++ b/include/string.h @@ -86,6 +86,13 @@ size_t strlcpy (char *, const char *, size_t); #ifdef _GNU_SOURCE #define strdupa(x) strcpy(alloca(strlen(x)+1),x) +#define strndupa(x, l) ({ \ + const char *__old = (x); \ + size_t __len = strnlen(__old, (l)); \ + char *__new = (char *)alloca(__len + 1); \ + __new[__len] = '\0'; \ + (char *)memcpy(__new, __old, __len); \ +}) int strverscmp (const char *, const char *); int strcasecmp_l (const char *, const char *, locale_t); int strncasecmp_l (const char *, const char *, size_t, locale_t);