patty/src/util.c
XANTRONIX Development 25da758257 Implement patty_strlcpy()
Implement patty_strlcpy() for portability and correctness, to provide
BSD strlcpy() functionality for glibc systems while ensuring a nul
terminated string is written to a destination, truncating the source
string by one byte if need be to make room for the nul terminator
2024-03-01 00:20:47 -05:00

17 lines
261 B
C

#include <patty/util.h>
ssize_t patty_strlcpy(char *dest, const char *src, size_t n) {
size_t i;
for (i=0; i<n-1; i++) {
dest[i] = src[i];
if (src[i] == '\0') {
break;
}
}
dest[i] = '\0';
return i;
}