summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/string.c b/lib/string.c
index 73b984123d..1b867ac09d 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -114,17 +114,21 @@ char * strncpy(char * dest,const char *src,size_t count)
* NUL-terminated string that fits in the buffer (unless,
* of course, the buffer size is zero). It does not pad
* out the result like strncpy() does.
+ *
+ * Return: the number of bytes copied
*/
size_t strlcpy(char *dest, const char *src, size_t size)
{
- size_t ret = strlen(src);
-
if (size) {
- size_t len = (ret >= size) ? size - 1 : ret;
+ size_t srclen = strlen(src);
+ size_t len = (srclen >= size) ? size - 1 : srclen;
+
memcpy(dest, src, len);
dest[len] = '\0';
+ return len + 1;
}
- return ret;
+
+ return 0;
}
#endif