]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add strlcpy() from libbsd or bird's own impl.
authorPavel Tvrdík <pawel.tvrdik@gmail.com>
Mon, 2 Nov 2015 15:49:06 +0000 (16:49 +0100)
committerPavel Tvrdík <pawel.tvrdik@gmail.com>
Mon, 2 Nov 2015 15:49:06 +0000 (16:49 +0100)
configure.in
lib/printf.c
lib/string.h
sysdep/autoconf.h.in

index c81709e61bf4fec0d099306845814002b92d1e1a..14a208e01ae7f753ba4cba6b5f79cc2b6ff86043 100644 (file)
@@ -262,6 +262,8 @@ if test "$enable_debug" = yes ; then
        fi
 fi
 
+AC_CHECK_LIB(bsd, strlcpy, LIBS="$LIBS -lbsd"; AC_DEFINE(HAVE_LIBBSD))
+
 CLIENT=
 CLIENT_LIBS=
 if test "$enable_client" = yes ; then
index e4cc3006797541975b1dc3df554d983bbf407b9c..8b4ddab7883d6943fcd1d38656457acd9850311f 100644 (file)
@@ -457,3 +457,32 @@ buffer_puts(buffer *buf, const char *str)
 
   buf->pos = bp;
 }
+
+#ifndef HAVE_LIBBSD
+/**
+ * strlcpy - BIRD's implementation of strlcpy()
+ *
+ * @dest: destination string
+ * @src: string must be NUL terminated
+ * @max_len: useable length in dest including the NUL terminator
+ * @return: the length of src string without the NUL terminator
+ *
+ * Size-bounded string copying and concatenation
+ */
+size_t
+strlcpy(char *dest, const char *src, size_t max_len)
+{
+  size_t len = strlen(src);
+
+  if (len < max_len)
+    memcpy(dest, src, len + 1);
+  else
+  {
+    max_len--;
+    memcpy(dest, src, max_len);
+    dest[max_len] = 0;
+  }
+
+  return len;
+}
+#endif
index 528a1a1924255b6ccf1eed05b4d120f2f4d6fe01..484f62ad77b4c81b7e8e154fd15a3f9f6b51782e 100644 (file)
@@ -24,4 +24,10 @@ void buffer_puts(buffer *buf, const char *str);
 
 int patmatch(byte *pat, byte *str);
 
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#else
+size_t strlcpy(char *dst, const char *src, size_t size);
+#endif
+
 #endif
index a9e46e274c2f85488bf4f3b2f88295404ad139a6..61958524160df3b96b27fd1190b690bda14c20c2 100644 (file)
@@ -66,4 +66,7 @@
 /* We have stdint.h */
 #undef HAVE_STDINT_H
 
+/* We have  <bsd/string.h> and strlcpy() */
+#undef HAVE_LIBBSD
+
 #define CONFIG_PATH ?