mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-11 17:13:56 -03:00
AP_Common: missing: Add definition for strndupa
`strndupa` is only available when using the GNU GCC suite. With this definition is possible to use the MUSL compiler. Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
This commit is contained in:
parent
5746943f50
commit
6e24880f87
15
libraries/AP_Common/missing/string.h
Normal file
15
libraries/AP_Common/missing/string.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include_next <string.h>
|
||||||
|
|
||||||
|
// Necessary for toolchains that does not provide `strndupa`, such as musl.
|
||||||
|
#if !defined(HAVE_DECL_STRNDUPA) && !defined(strndupa)
|
||||||
|
// The last value of the GCC extension "statement exprs" will be
|
||||||
|
// evaluated and returned, E.g: `#define foo(n) ({ n; })` is equivalent for
|
||||||
|
// `auto foo(auto n) { return n; }`
|
||||||
|
#define strndupa(old_string, len) \
|
||||||
|
({ \
|
||||||
|
const size_t string_len = strnlen(old_string, len); \
|
||||||
|
char *new_string = static_cast<char*>(alloca(string_len + 1)); \
|
||||||
|
new_string[string_len] = '\0'; \
|
||||||
|
static_cast<char*>(memcpy(new_string, old_string, len)); \
|
||||||
|
})
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user