CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Common/missing/string.h
Views: 1799
1
#include_next <string.h>
2
3
// Necessary for toolchains that does not provide `strndupa`, such as musl.
4
#if !defined(HAVE_DECL_STRNDUPA) && !defined(strndupa)
5
// The last value of the GCC extension "statement exprs" will be
6
// evaluated and returned, E.g: `#define foo(n) ({ n; })` is equivalent for
7
// `auto foo(auto n) { return n; }`
8
#define strndupa(old_string, len) \
9
({ \
10
const size_t string_len = strnlen(old_string, len); \
11
char *new_string = static_cast<char*>(alloca(string_len + 1)); \
12
new_string[string_len] = '\0'; \
13
static_cast<char*>(memcpy(new_string, old_string, len)); \
14
})
15
#endif
16
17