commit d56297fed58c06e726860efbd7be4c72bfc4429e
parent 9d9bd91369117238963de553f570318b6fb42437
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:
2 files changed, 25 insertions(+), 5 deletions(-)
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
-
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)