mirror of https://code.videolan.org/videolan/vlc
strlcpy: simplify
This commit is contained in:
parent
a50366bc97
commit
893432c251
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue