mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-12 13:30:15 -05:00
Provide a strndupa implementation when it is absent
strndupa is a glibc exclusive, not even musl implements it
This commit is contained in:
parent
cc0386e1c5
commit
90ade199e6
2 changed files with 20 additions and 0 deletions
|
|
@ -29,6 +29,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/pod/pod.h>
|
||||
|
||||
|
|
@ -52,6 +54,20 @@ pw_free_strv(char **str);
|
|||
char *
|
||||
pw_strip(char *str, const char *whitespace);
|
||||
|
||||
#if defined(HAVE_STRNDUPA)
|
||||
#include <string.h>
|
||||
#else
|
||||
# define strndupa(s, n) \
|
||||
({ \
|
||||
const char *__old = (s); \
|
||||
size_t __len = strnlen(__old, (n)); \
|
||||
char *__new = (char *) __builtin_alloca(__len + 1); \
|
||||
memcpy(__new, __old, __len); \
|
||||
__new[__len] = '\0'; \
|
||||
__new; \
|
||||
})
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue