strncpy.c (226B)
1 #include <string.h> 2 #undef strncpy 3 4 char * 5 strncpy(char * restrict dst, const char * restrict src, size_t n) 6 { 7 char *ret = dst; 8 9 for (; n > 0 && *src; --n) 10 *dst++ = *src++; 11 while (n-- > 0) 12 *dst++ = '\0'; 13 return ret; 14 }