Commit e547061f authored by Pavel Tvrdík's avatar Pavel Tvrdík
Browse files

Add strlcpy() from libbsd or bird's own impl.

parent 6e69fcbd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+29 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -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 ?