mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 17:50:04 +01:00
[liba] Add strlcat
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#if (__GLIBC__ || __MINGW32__)
|
||||
#include "strlcat.c"
|
||||
#include "strlcpy.c"
|
||||
#endif
|
||||
|
||||
19
liba/src/strlcat.c
Normal file
19
liba/src/strlcat.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <string.h>
|
||||
|
||||
size_t strlcat(char * dst, const char * src, size_t dstSize) {
|
||||
const size_t srcLen = strlen(src);
|
||||
size_t dstLen = strlen(dst);
|
||||
if (dstLen > dstSize) {
|
||||
dstLen = dstSize;
|
||||
}
|
||||
if (dstLen == dstSize) {
|
||||
return dstSize+srcLen;
|
||||
}
|
||||
if (srcLen < dstSize-dstLen) {
|
||||
memcpy(dst+dstLen, src, srcLen+1);
|
||||
} else {
|
||||
memcpy(dst+dstLen, src, dstSize-1);
|
||||
dst[dstLen+dstSize-1] = 0;
|
||||
}
|
||||
return dstLen+srcLen;
|
||||
}
|
||||
Reference in New Issue
Block a user