LibC: Fix strncat

strncat was using strncpy internally which nullpadded dest until n bytes
were written.

also there was no terminating null byte added if src was shorter than n
bytes
This commit is contained in:
Bananymous 2025-04-17 23:12:40 +03:00
parent bdbde25784
commit 88abbd90dc
1 changed files with 4 additions and 1 deletions

View File

@ -147,7 +147,10 @@ char* strcat(char* __restrict__ dest, const char* __restrict__ src)
char* strncat(char* __restrict__ dest, const char* __restrict__ src, size_t n)
{
strncpy(dest + strlen(dest), src, n);
dest += strlen(dest);
while (*src && n--)
*dest++ = *src++;
*dest = '\0';
return dest;
}