diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 561c278ab..f2faad486 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,8 @@ +2011-06-09 Yaakov Selkowitz + + * libc/include/string.h (strdupa): New macro function. + (strndupa): New macro function. + 2011-05-27 Nick Clifton * libc/sys/sysnecv850/sbrk.c (_sbrk): Tidy code. diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h index d565e8e32..cd80ce76b 100644 --- a/newlib/libc/include/string.h +++ b/newlib/libc/include/string.h @@ -99,6 +99,20 @@ int _EXFUN(strtosigno, (const char *__name)); /* Recursive version of strerror. */ char * _EXFUN(_strerror_r, (struct _reent *, int, int, int *)); +#if defined _GNU_SOURCE && defined __GNUC__ +#define strdupa(__s) \ + (__extension__ ({const char *__in = (__s); \ + size_t __len = strlen (__in) + 1; \ + char * __out = (char *) __builtin_alloca (__len); \ + (char *) memcpy (__out, __in, __len);})) +#define strndupa(__s, __n) \ + (__extension__ ({const char *__in = (__s); \ + size_t __len = strnlen (__in, (__n)) + 1; \ + char *__out = (char *) __builtin_alloca (__len); \ + __out[__len-1] = '\0'; \ + (char *) memcpy (__out, __in, __len-1);})) +#endif /* _GNU_SOURCE && __GNUC__ */ + /* These function names are used on Windows and perhaps other systems. */ #ifndef strcmpi #define strcmpi strcasecmp