LibC: Implement and fix some string.h functions

This commit is contained in:
Bananymous 2023-12-06 18:13:34 +02:00
parent 393ac33e3c
commit 76049b2e13
1 changed files with 24 additions and 11 deletions

View File

@ -71,15 +71,38 @@ char* stpcpy(char* __restrict__ dest, const char* __restrict__ src)
return &dest[i];
}
char* stpncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
{
size_t i = 0;
for (; src[i] && n; i++, n--)
dest[i] = src[i];
for (; n; i++, n--)
dest[i] = '\0';
dest[i] = '\0';
return &dest[i];
}
char* strcpy(char* __restrict__ dest, const char* __restrict__ src)
{
stpcpy(dest, src);
return dest;
}
char* strncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
{
stpncpy(dest, src, n);
return dest;
}
char* strcat(char* __restrict__ dest, const char* __restrict__ src)
{
strcpy(dest + strlen(src), src);
strcpy(dest + strlen(dest), src);
return dest;
}
char* strncat(char* __restrict__ dest, const char* __restrict__ src, size_t n)
{
strncpy(dest + strlen(dest), src, n);
return dest;
}
@ -321,16 +344,6 @@ char* strchrnul(const char* str, int c)
return (char*)str;
}
char* strncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n)
{
size_t i;
for (i = 0; src[i] && i < n; i++)
dest[i] = src[i];
for (; i < n; i++)
dest[i] = '\0';
return dest;
}
char* strstr(const char* haystack, const char* needle)
{
for (size_t i = 0; haystack[i]; i++)