toaruos/libc/string/strncpy.c
2018-11-27 18:41:50 +09:00

18 lines
257 B
C

#include <string.h>
char * strncpy(char * dest, const char * src, size_t n) {
char * out = dest;
while (n > 0) {
if (!*src) break;
*out = *src;
++out;
++src;
--n;
}
for (int i = 0; i < (int)n; ++i) {
*out = '\0';
++out;
}
return out;
}