diff --git a/include/string.h b/include/string.h index f876ae8f8c..965acf6ee5 100644 --- a/include/string.h +++ b/include/string.h @@ -29,15 +29,25 @@ #include #include +#include /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #define strcoll_l(s1, s2, l) strcoll(s1, s2) +#define strdupa(x) strcpy(alloca(strlen(x) + 1), x) #define strerror_l(e, l) strerror(e) #define strxfrm_l(s1, s2, n, l) strxfrm(s1, s2, n) +#define strndupa(x, l) ({ \ + FAR const char *__old = (x); \ + size_t __len = strnlen(__old, (l)); \ + FAR char *__new = alloca(__len + 1); \ + __new[__len] = '\0'; \ + (FAR char *)memcpy(__new, __old, __len); \ +}) + /**************************************************************************** * Public Function Prototypes ****************************************************************************/