Skip to content

Commit 6718594

Browse files
committed
Fixing strncat
1 parent af8c834 commit 6718594

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

libc/include/string.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,15 @@ static __inline__ size_t strlen(const char * s) {
9696

9797
static __inline__ char * strncat(char * s1, const char * s2, size_t n) {
9898
char * r = s1;
99+
char c;
99100

100101
while (*s1)
101102
s1++;
102-
strncpy(s1, s2, n);
103+
104+
while (n-- && ((c = *s2++)))
105+
*s1++ = c;
106+
107+
*s1 = 0;
103108

104109
return r;
105110
}

0 commit comments

Comments
 (0)