ref: c42057cb7f05df361506718c77a1fb36a2f38e5b
parent: 69b5a8019cbd3df428f00665f56331ee9bdace41
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Feb 16 17:07:30 EST 2017
[libc] Add strncpy()
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -2,7 +2,7 @@
.POSIX:
LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
- strrchr.o strcat.o
+ strrchr.o strcat.o strncpy.o
all: libc.a
--- /dev/null
+++ b/libc/src/strncpy.c
@@ -1,0 +1,15 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+char *
+strncpy(char *dst, const char *src, size_t n)
+{
+ char *ret = dst;
+
+ while (n > 0 && (*dst++ = *src++))
+ /* nothing */;
+ while (n-- > 0)
+ *dst++ = '\0';
+ return ret;
+}