mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[liba] Improve strlcpy
Use memcpy (can be optimized) and return the correct size
This commit is contained in:
@@ -1,17 +1,12 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlcpy(char * dst, const char * src, size_t dstSize) {
|
||||
if (dstSize == 0) {
|
||||
return strlen(src);
|
||||
const size_t srcLen = strlen(src);
|
||||
if (srcLen+1 < dstSize) {
|
||||
memcpy(dst, src, srcLen+1);
|
||||
} else if (dstSize != 0) {
|
||||
memcpy(dst, src, dstSize-1);
|
||||
dst[dstSize-1] = 0;
|
||||
}
|
||||
const char * cur = src;
|
||||
const char * end = src+dstSize-1;
|
||||
while (*cur != 0 && cur < end) {
|
||||
*dst++ = *cur++;
|
||||
}
|
||||
*dst = 0;
|
||||
while (*cur != 0) {
|
||||
cur++;
|
||||
}
|
||||
return cur-src;
|
||||
return srcLen;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user