userspace/libc: implement strncpy function

Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
EnderIce2 2025-02-12 02:42:51 +02:00
parent 23a17fae00
commit 24fd486764
No known key found for this signature in database
GPG Key ID: 2EE20AF089811A5A
2 changed files with 14 additions and 2 deletions

View File

@ -51,7 +51,7 @@ extern "C"
size_t strlen(const char *s);
char *strncat(char *restrict, const char *restrict, size_t);
int strncmp(const char *s1, const char *s2, size_t n);
char *strncpy(char *restrict, const char *restrict, size_t);
char *strncpy(char *restrict s1, const char *restrict s2, size_t n);
char *strndup(const char *, size_t);
size_t strnlen(const char *, size_t);
char *strpbrk(const char *s1, const char *s2);

View File

@ -124,7 +124,19 @@ export int strncmp(const char *s1, const char *s2, size_t n)
return 0;
}
export char *strncpy(char *restrict, const char *restrict, size_t);
export char *strncpy(char *restrict s1, const char *restrict s2, size_t n)
{
char *dest = s1;
while (n && (*dest++ = *s2++))
n--;
if (n)
while (--n)
*dest++ = '\0';
return s1;
}
export char *strndup(const char *, size_t);
export size_t strnlen(const char *, size_t);