scc

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

commit 446d6cf7334ec3d1532ab59611d58889467c5004
parent b9cbec6574530d25f2499037a48b3f8c730367ec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 16 Feb 2017 22:37:23 +0100

[libc] Add strncat()

Diffstat:
libc/src/Makefile | 2+-
libc/src/strncat.c | 16++++++++++++++++
2 files changed, 17 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 strncpy.o + strrchr.o strcat.o strncpy.o strncat.o all: libc.a diff --git a/libc/src/strncat.c b/libc/src/strncat.c @@ -0,0 +1,16 @@ +/* See LICENSE file for copyright and license details. */ + +#include <string.h> + +char * +strncat(char *dst, const char *src, size_t n) +{ + char *ret = dst; + + while (*dst) + ++dst; + while (n-- > 0 && *src) + *dst++ = *src++; + *dst = '\0'; + return ret; +}