From 6718594071fe39014179f47b5d5fe395668b93ca Mon Sep 17 00:00:00 2001 From: Nicolas 'Pixel' Noble Date: Tue, 14 Jul 2020 22:52:40 -0700 Subject: [PATCH] Fixing strncat --- libc/include/string.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libc/include/string.h b/libc/include/string.h index 3c6c9c6..2cb3802 100644 --- a/libc/include/string.h +++ b/libc/include/string.h @@ -96,10 +96,15 @@ static __inline__ size_t strlen(const char * s) { static __inline__ char * strncat(char * s1, const char * s2, size_t n) { char * r = s1; + char c; while (*s1) s1++; - strncpy(s1, s2, n); + + while (n-- && ((c = *s2++))) + *s1++ = c; + + *s1 = 0; return r; }