scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit b9cbec6574530d25f2499037a48b3f8c730367ec
parent 6b7f10769a17d19ca3b3e2f3ed4e42d6ca9dd4c2
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 16 Feb 2017 22:07:30 +0100

[libc] Add strncpy()

Diffstat:
Mlibc/src/Makefile | 2+-
Alibc/src/strncpy.c | 15+++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)

diff --git 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 diff --git a/libc/src/strncpy.c b/libc/src/strncpy.c @@ -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; +}