mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-18 06:51:54 +00:00
Add strlcpy() from libbsd or bird's own impl.
This commit is contained in:
parent
6e69fcbdfc
commit
e547061f33
@ -262,6 +262,8 @@ if test "$enable_debug" = yes ; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_CHECK_LIB(bsd, strlcpy, LIBS="$LIBS -lbsd"; AC_DEFINE(HAVE_LIBBSD))
|
||||||
|
|
||||||
CLIENT=
|
CLIENT=
|
||||||
CLIENT_LIBS=
|
CLIENT_LIBS=
|
||||||
if test "$enable_client" = yes ; then
|
if test "$enable_client" = yes ; then
|
||||||
|
29
lib/printf.c
29
lib/printf.c
@ -457,3 +457,32 @@ buffer_puts(buffer *buf, const char *str)
|
|||||||
|
|
||||||
buf->pos = bp;
|
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
|
||||||
|
@ -24,4 +24,10 @@ void buffer_puts(buffer *buf, const char *str);
|
|||||||
|
|
||||||
int patmatch(byte *pat, byte *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
|
#endif
|
||||||
|
@ -66,4 +66,7 @@
|
|||||||
/* We have stdint.h */
|
/* We have stdint.h */
|
||||||
#undef HAVE_STDINT_H
|
#undef HAVE_STDINT_H
|
||||||
|
|
||||||
|
/* We have <bsd/string.h> and strlcpy() */
|
||||||
|
#undef HAVE_LIBBSD
|
||||||
|
|
||||||
#define CONFIG_PATH ?
|
#define CONFIG_PATH ?
|
||||||
|
Loading…
Reference in New Issue
Block a user