]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
configure: check for strlcat & strlcpy
authorBernd Kuhls <bernd.kuhls@t-online.de>
Sat, 23 Jun 2018 18:47:26 +0000 (20:47 +0200)
committerJaroslav Kysela <perex@perex.cz>
Sun, 1 Jul 2018 09:50:30 +0000 (11:50 +0200)
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

configure
src/tvh_string.h

index 0857a1958d8e0cc7fd731651c119400dc23f7af3..b183d02b328367e2e5bd205bcd4673d87ae54d7a 100755 (executable)
--- a/configure
+++ b/configure
@@ -159,6 +159,20 @@ else
   COMPILER=gcc
 fi
 
+check_cc_snippet strlcat '#include <string.h>
+int test(int argc, char **argv) {
+  char dst[10];
+  strlcat("test", dst, sizeof(dst));
+  return 0;
+}'
+
+check_cc_snippet strlcpy '#include <string.h>
+int test(int argc, char **argv) {
+  char dst[10];
+  strlcpy("test", dst, sizeof(dst));
+  return 0;
+}'
+
 check_cc_snippet getloadavg '#include <stdlib.h>
 void test() { getloadavg(NULL,0); }'
 
index 87d8c3320bf68f86c1102f9bd847fb7f704155d7..13ef2f308e06059d717e91a7533ca20d2f56af90 100644 (file)
@@ -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); \