diff options
author | Romain Naour <romain.naour@openwide.fr> | 2015-07-30 17:31:31 +0200 |
---|---|---|
committer | Romain Naour <romain.naour@openwide.fr> | 2015-07-31 14:57:27 +0200 |
commit | 0e2be0c217028e73073e7f9ccb010cc8b4d756db (patch) | |
tree | 1059dbdd145e2b329d22838d7037a888ae81bb51 /src/shared/missing.h | |
parent | 24ccb6ebc5e13a128aaedd3a2eb52eef3adf6dcd (diff) |
build-sys: check for strndupa
strndupa is a GNU extension, therefore it's not available
for all libc libraries (musl).
This patch is based on the one proposed by Emil Renner Berthing for
systemd [1].
[1] http://lists.freedesktop.org/archives/systemd-devel/2014-September/023190.html
Signed-off-by: Romain Naour <romain.naour@openwide.fr>
Diffstat (limited to 'src/shared/missing.h')
-rw-r--r-- | src/shared/missing.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/missing.h b/src/shared/missing.h index 2dc9d842d3..9031119a45 100644 --- a/src/shared/missing.h +++ b/src/shared/missing.h @@ -158,3 +158,14 @@ static inline int name_to_handle_at(int fd, const char *name, struct file_handle #ifndef AT_EMPTY_PATH #define AT_EMPTY_PATH 0x1000 #endif + +#if !HAVE_DECL_STRNDUPA +#define strndupa(s, n) \ + ({ \ + const char *__old = (s); \ + size_t __len = strnlen(__old, (n)); \ + char *__new = (char *)alloca(__len + 1); \ + __new[__len] = '\0'; \ + (char *)memcpy(__new, __old, __len); \ + }) +#endif |