Implement strlcpy to avoid entire libbsd dependency on Linux.

Signed-off-by: Christoph Lohmann <20h@r-36.net>
master
parazyd 2020-05-05 10:50:40 +02:00 committed by Christoph Lohmann
parent 9d9bd91369
commit d56297fed5
2 changed files with 25 additions and 5 deletions

View File

@ -1,4 +1,3 @@
VERSION="0.3"
# paths
@ -10,12 +9,10 @@ INCS = -I. -I/usr/include
# BSD
#LIBS = -L/usr/lib -lc
# Linux
LIBS = -L/usr/lib -lc -lbsd
# flags
# Linux
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=1
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_POSIX_C_SOURCE=200809L -DNEED_STRLCPY
# BSD
#CPPFLAGS = -DVERSION=\"${VERSION}\"
@ -24,4 +21,3 @@ LDFLAGS += -g ${LIBS}
# compiler and linker
# CC = cc

View File

@ -8,6 +8,30 @@
#include <string.h>
#include <unistd.h>
#ifdef NEED_STRLCPY /* OpenBSD implementation */
size_t
strlcpy(char *dst, const char *src, size_t dsize) {
const char *osrc = src;
size_t nleft = dsize;
if (nleft != 0) {
while (--nleft != 0) {
if ((*dst++= *src++) == '\0')
break;
}
}
if (nleft == 0) {
if (dsize != 0)
*dst = '\0';
while (*src++)
;
}
return(src - osrc - 1);
}
#endif /* NEED_STRLCPY */
/* from git://bitreich.org/utf8expr */
size_t
utf8strlen(const char *s)