Skip to content

Commit e26ce33

Browse files
bkuhlsperexg
authored andcommitted
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
1 parent 30f9f7f commit e26ce33

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

‎configure‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ else
159159
COMPILER=gcc
160160
fi
161161

162+
check_cc_snippet strlcat '#include <string.h>
163+
int test(int argc, char **argv) {
164+
char dst[10];
165+
strlcat("test", dst, sizeof(dst));
166+
return 0;
167+
}'
168+
169+
check_cc_snippet strlcpy '#include <string.h>
170+
int test(int argc, char **argv) {
171+
char dst[10];
172+
strlcpy("test", dst, sizeof(dst));
173+
return 0;
174+
}'
175+
162176
check_cc_snippet getloadavg '#include <stdlib.h>
163177
void test() { getloadavg(NULL,0); }'
164178

‎src/tvh_string.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static inline const char *tvh_strbegins(const char *s1, const char *s2)
4747
return s1;
4848
}
4949

50+
#ifndef ENABLE_STRLCPY
5051
static inline size_t strlcpy(char *dst, const char *src, size_t size)
5152
{
5253
size_t ret = strlen(src);
@@ -57,7 +58,9 @@ static inline size_t strlcpy(char *dst, const char *src, size_t size)
5758
}
5859
return ret;
5960
}
61+
#endif
6062

63+
#ifndef ENABLE_STRLCAT
6164
static inline size_t strlcat(char *dst, const char *src, size_t count)
6265
{
6366
size_t dlen = strlen(dst);
@@ -72,6 +75,7 @@ static inline size_t strlcat(char *dst, const char *src, size_t count)
7275
dst[len] = '\0';
7376
return res;
7477
}
78+
#endif
7579

7680
#define tvh_strlcatf(buf, size, ptr, fmt...) \
7781
do { int __r = snprintf((buf) + ptr, (size) - ptr, fmt); \

0 commit comments

Comments
 (0)