Implement strlcpy to avoid entire libbsd dependency on Linux. - pointtools - Simple point utilities to hold text presentations. HTML git clone git://bitreich.org/pointtools/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/pointtools/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit d56297fed58c06e726860efbd7be4c72bfc4429e DIR parent 9d9bd91369117238963de553f570318b6fb42437 HTML Author: parazyd <parazyd@dyne.org> Date: Tue, 5 May 2020 10:50:40 +0200 Implement strlcpy to avoid entire libbsd dependency on Linux. Signed-off-by: Christoph Lohmann <20h@r-36.net> Diffstat: M config.mk | 6 +----- M md2point.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) --- DIR diff --git a/config.mk b/config.mk @@ -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 - DIR diff --git a/md2point.c b/md2point.c @@ -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)