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
17 lines
261 B
C
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;
|
|
}
|