utils: provide strdupa() if not in libc

FreeBSD does not have strdupa(), provide it locally then.

Macro by: Gleb Popov <arrowd@FreeBSD.org>
This commit is contained in:
Evgeniy Khramtsov 2021-05-11 21:01:55 +03:00
parent c89af625db
commit 685ff1dc25
2 changed files with 11 additions and 0 deletions

View file

@ -40,6 +40,7 @@
#include <spa/param/profiler.h>
#include <spa/debug/pod.h>
#include <pipewire/utils.h>
#include <pipewire/private.h>
#include <pipewire/impl.h>
#include <extensions/profiler.h>

View file

@ -66,6 +66,16 @@ pw_strip(char *str, const char *whitespace);
})
#endif
#if !defined(strdupa)
# define strdupa(s) \
({ \
const char *__old = (s); \
size_t __len = strlen(__old) + 1; \
char *__new = (char *) alloca(__len); \
(char *) memcpy(__new, __old, __len); \
})
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif