string.h: add strndupa
This commit is contained in:
parent
18daae3135
commit
6310769c3c
1 changed files with 7 additions and 0 deletions
|
|
@ -86,6 +86,13 @@ size_t strlcpy (char *, const char *, size_t);
|
||||||
|
|
||||||
#ifdef _GNU_SOURCE
|
#ifdef _GNU_SOURCE
|
||||||
#define strdupa(x) strcpy(alloca(strlen(x)+1),x)
|
#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 strverscmp (const char *, const char *);
|
||||||
int strcasecmp_l (const char *, const char *, locale_t);
|
int strcasecmp_l (const char *, const char *, locale_t);
|
||||||
int strncasecmp_l (const char *, const char *, size_t, locale_t);
|
int strncasecmp_l (const char *, const char *, size_t, locale_t);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue