From 1f879e4b930fef71f030e5b6e5fae359f27d1aec Mon Sep 17 00:00:00 2001 From: Bernd Kuhls Date: Sat, 23 Jun 2018 20:47:26 +0200 Subject: [PATCH] configure: check for strlcat & strlcpy Building tvheadend with uclibc and musl fails: src/tvh_string.h:50:22: error: static declaration of 'strlcpy' follows non-static declaration static inline size_t strlcpy(char *dst, const char *src, size_t size) src/tvh_string.h:61:22: error: static declaration of 'strlcat' follows non-static declaration static inline size_t strlcat(char *dst, const char *src, size_t count) because they provide strlcat & strlcpy: https://sourceware.org/glibc/wiki/strlcpy This patch adds configure checks and makes the implementation in tvh_string.h optional, the configure log looks like this: glibc checking for cc strlcat ... fail checking for cc strlcpy ... fail musl checking for cc strlcat ... ok checking for cc strlcpy ... ok uclibc checking for cc strlcat ... ok checking for cc strlcpy ... ok Patch sent upstream: https://github.com/tvheadend/tvheadend/pull/1133 Signed-off-by: Bernd Kuhls --- configure | 14 ++++++++++++++ src/tvh_string.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/configure b/configure index 0857a1958..b183d02b3 100755 --- a/configure +++ b/configure @@ -159,6 +159,20 @@ else COMPILER=gcc fi +check_cc_snippet strlcat '#include +int test(int argc, char **argv) { + char dst[10]; + strlcat("test", dst, sizeof(dst)); + return 0; +}' + +check_cc_snippet strlcpy '#include +int test(int argc, char **argv) { + char dst[10]; + strlcpy("test", dst, sizeof(dst)); + return 0; +}' + check_cc_snippet getloadavg '#include void test() { getloadavg(NULL,0); }' diff --git a/src/tvh_string.h b/src/tvh_string.h index 87d8c3320..13ef2f308 100644 --- a/src/tvh_string.h +++ b/src/tvh_string.h @@ -47,6 +47,7 @@ static inline const char *tvh_strbegins(const char *s1, const char *s2) return s1; } +#ifndef ENABLE_STRLCPY static inline size_t strlcpy(char *dst, const char *src, size_t size) { size_t ret = strlen(src); @@ -57,7 +58,9 @@ static inline size_t strlcpy(char *dst, const char *src, size_t size) } return ret; } +#endif +#ifndef ENABLE_STRLCAT static inline size_t strlcat(char *dst, const char *src, size_t count) { size_t dlen = strlen(dst); @@ -72,6 +75,7 @@ static inline size_t strlcat(char *dst, const char *src, size_t count) dst[len] = '\0'; return res; } +#endif #define tvh_strlcatf(buf, size, ptr, fmt...) \ do { int __r = snprintf((buf) + ptr, (size) - ptr, fmt); \ -- 2.17.1