0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 09:58:43 +00:00

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

This commit is contained in:
Pavel Tvrdík 2015-11-02 16:49:06 +01:00
parent 6e69fcbdfc
commit e547061f33
4 changed files with 40 additions and 0 deletions

View 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

View 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

View 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

View 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 ?