core-util: rework pa_strlcpy() to not rely on strncpy()

strncpy() is very slow since it resets the entire destination buffer.
Replace usage of strncpy by memcpy().
This commit is contained in:
Lennart Poettering 2009-08-01 02:01:58 +02:00
parent e5c2256e36
commit c6ea9fecc9

View file

@ -552,12 +552,20 @@ char *pa_vsprintf_malloc(const char *format, va_list ap) {
/* Similar to OpenBSD's strlcpy() function */ /* Similar to OpenBSD's strlcpy() function */
char *pa_strlcpy(char *b, const char *s, size_t l) { char *pa_strlcpy(char *b, const char *s, size_t l) {
size_t k;
pa_assert(b); pa_assert(b);
pa_assert(s); pa_assert(s);
pa_assert(l > 0); pa_assert(l > 0);
strncpy(b, s, l); k = strlen(s);
b[l-1] = 0;
if (k > l-1)
k = l-1;
memcpy(b, s, k);
b[k] = 0;
return b; return b;
} }