string/strdupa: support strdupa strndupa
refs:https://sites.uclouvain.be/SystInfo/manpages/man3/strdup.3.html Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
7660ece921
commit
191d453063
|
@ -29,15 +29,25 @@
|
|||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <alloca.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
****************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue