mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add strdupa(3) and strndupa(3).
This commit is contained in:
parent
fdbcea19dc
commit
0c43765bbf
1 changed files with 21 additions and 0 deletions
|
@ -93,6 +93,27 @@ char* strerror_l(int, locale_t);
|
|||
char* strsignal(int signum);
|
||||
#endif
|
||||
|
||||
/* Duplicate S, returning an identical alloca'd string. */
|
||||
#define strdupa(s) \
|
||||
(__extension__ \
|
||||
({ \
|
||||
const char* __old = (s); \
|
||||
size_t __len = strlen(__old) + 1; \
|
||||
char* __new = (char*) __builtin_alloca(__len); \
|
||||
(char*) memcpy(__new, __old, __len); \
|
||||
}))
|
||||
|
||||
/* Return an alloca'd copy of at most N bytes of string. */
|
||||
#define strndupa(s, n) \
|
||||
(__extension__ \
|
||||
({ \
|
||||
__const char* __old = (s); \
|
||||
size_t __len = strnlen(__old, (n)); \
|
||||
char* __new = (char*) __builtin_alloca(__len + 1); \
|
||||
__new[__len] = '\0'; \
|
||||
(char*) memcpy(__new, __old, __len); \
|
||||
}))
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue