[hackers] [scc] [libc] Add strncpy() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 16 Feb 2017 22:09:03 +0100 (CET)

commit b9cbec6574530d25f2499037a48b3f8c730367ec
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Feb 16 22:07:30 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Feb 16 22:07:30 2017 +0100

    [libc] Add strncpy()

diff --git a/libc/src/Makefile b/libc/src/Makefile
index 4d83879..4de1e42 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -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
 
diff --git a/libc/src/strncpy.c b/libc/src/strncpy.c
new file mode 100644
index 0000000..0670c6a
--- /dev/null
+++ b/libc/src/strncpy.c
_AT_@ -0,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;
+}
Received on Thu Feb 16 2017 - 22:09:03 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 16 2017 - 22:12:22 CET