Skip to content

Commit 4f6b733

Browse files
baruchsiachshemminger
authored andcommitted
lib: fix multiple strlcpy definition
Some C libraries, like uClibc and musl, provide BSD compatible strlcpy(). Add check_strlcpy() to configure, and avoid defining strlcpy and strlcat when the C library provides them. This fixes the following static link error with uClibc-ng: .../sysroot/usr/lib/libc.a(strlcpy.os): In function `strlcpy': strlcpy.c:(.text+0x0): multiple definition of `strlcpy' ../lib/libutil.a(utils.o):utils.c:(.text+0x1ddc): first defined here collect2: error: ld returned 1 exit status Acked-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Baruch Siach <baruch@tkos.co.il>
1 parent ecd44e6 commit 4f6b733

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

configure

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,27 @@ EOF
326326
rm -f $TMPDIR/dbtest.c $TMPDIR/dbtest
327327
}
328328

329+
check_strlcpy()
330+
{
331+
cat >$TMPDIR/strtest.c <<EOF
332+
#include <string.h>
333+
int main(int argc, char **argv) {
334+
char dst[10];
335+
strlcpy(dst, "test", sizeof(dst));
336+
return 0;
337+
}
338+
EOF
339+
$CC -I$INCLUDE -o $TMPDIR/strtest $TMPDIR/strtest.c >/dev/null 2>&1
340+
if [ $? -eq 0 ]
341+
then
342+
echo "no"
343+
else
344+
echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
345+
echo "yes"
346+
fi
347+
rm -f $TMPDIR/strtest.c $TMPDIR/strtest
348+
}
349+
329350
quiet_config()
330351
{
331352
cat <<EOF
@@ -397,6 +418,9 @@ check_mnl
397418
echo -n "Berkeley DB: "
398419
check_berkeley_db
399420

421+
echo -n "need for strlcpy: "
422+
check_strlcpy
423+
400424
echo
401425
echo -n "docs:"
402426
check_docs

lib/utils.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ int get_real_family(int rtm_type, int rtm_family)
12601260
return rtm_family;
12611261
}
12621262

1263+
#ifdef NEED_STRLCPY
12631264
size_t strlcpy(char *dst, const char *src, size_t size)
12641265
{
12651266
size_t srclen = strlen(src);
@@ -1282,3 +1283,4 @@ size_t strlcat(char *dst, const char *src, size_t size)
12821283

12831284
return dlen + strlcpy(dst + dlen, src, size - dlen);
12841285
}
1286+
#endif

0 commit comments

Comments
 (0)