diff options
Diffstat (limited to 'usr/klibc/strncpy.c')
-rw-r--r-- | usr/klibc/strncpy.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/usr/klibc/strncpy.c b/usr/klibc/strncpy.c new file mode 100644 index 0000000..fffc118 --- /dev/null +++ b/usr/klibc/strncpy.c @@ -0,0 +1,24 @@ +/* + * strncpy.c + */ + +#include <string.h> + +char *strncpy(char *dst, const char *src, size_t n) +{ + char *q = dst; + const char *p = src; + char ch; + + while (n) { + n--; + *q++ = ch = *p++; + if (!ch) + break; + } + + /* The specs say strncpy() fills the entire buffer with NUL. Sigh. */ + memset(q, 0, n); + + return dst; +} |