summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/core-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-08-01 02:01:58 +0200
committerLennart Poettering <lennart@poettering.net>2009-08-01 02:01:58 +0200
commitc6ea9fecc9acd70642ae45b01300484f6b900c6b (patch)
treeb79718b09c89c88965969752b6e8f46cc49d86be /src/pulsecore/core-util.c
parente5c2256e360df3662295b8cc0594568e425e8679 (diff)
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().
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r--src/pulsecore/core-util.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index d01efa23..99644d7c 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -552,12 +552,20 @@ char *pa_vsprintf_malloc(const char *format, va_list ap) {
/* Similar to OpenBSD's strlcpy() function */
char *pa_strlcpy(char *b, const char *s, size_t l) {
+ size_t k;
+
pa_assert(b);
pa_assert(s);
pa_assert(l > 0);
- strncpy(b, s, l);
- b[l-1] = 0;
+ k = strlen(s);
+
+ if (k > l-1)
+ k = l-1;
+
+ memcpy(b, s, k);
+ b[k] = 0;
+
return b;
}