Add BSD compatible strlcpy function (uc_strlcpy)

This commit is contained in:
Nils O. Selåsdal
2014-01-08 00:37:33 +01:00
parent 0e2d4f07c3
commit 3e313932af
2 changed files with 29 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
#include <string.h>
size_t uc_strlcpy(char *dst, const char *src, size_t max)
{
size_t len = strlen(src);
if (max != 0) {
if (len >= max) {
memcpy(dst, src, max - 1);
dst[max - 1] = 0;
} else {
memcpy(dst, src, len + 1);
}
}
return len;
}