Commit 893432c2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

strlcpy: simplify

parent a50366bc
......@@ -22,7 +22,7 @@
# include <config.h>
#endif
#include <stddef.h>
#include <string.h>
/**
* Copy a string to a sized buffer. The result is always nul-terminated
......@@ -37,16 +37,13 @@
*/
size_t strlcpy (char *tgt, const char *src, size_t bufsize)
{
size_t length;
size_t length = strlen(src);
for (length = 1; (length < bufsize) && *src; length++)
*tgt++ = *src++;
if (bufsize > length)
memcpy(tgt, src, length + 1);
else
if (bufsize > 0)
memcpy(tgt, src, bufsize - 1), tgt[bufsize - 1] = '\0';
if (bufsize)
*tgt = '\0';
while (*src++)
length++;
return length - 1;
return length;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment