From 6dfefc90c41acc6fbb9391ba5346734769f1bec4 Mon Sep 17 00:00:00 2001 From: EnderIce2 Date: Fri, 14 Feb 2025 20:07:20 +0200 Subject: [PATCH] feat(userspace/libc): implement strcpy function Add strcpy implementation in string.c Signed-off-by: EnderIce2 --- Userspace/libc/include/string.h | 2 +- Userspace/libc/src/std/string.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Userspace/libc/include/string.h b/Userspace/libc/include/string.h index 72e05dfe..59ce07c4 100644 --- a/Userspace/libc/include/string.h +++ b/Userspace/libc/include/string.h @@ -40,7 +40,7 @@ extern "C" int strcmp(const char *s1, const char *s2); int strcoll(const char *s1, const char *s2); int strcoll_l(const char *, const char *, locale_t); - char *strcpy(char *restrict, const char *restrict); + char *strcpy(char *restrict s1, const char *restrict s2); size_t strcspn(const char *s1, const char *s2); char *strdup(const char *); char *strerror(int); diff --git a/Userspace/libc/src/std/string.c b/Userspace/libc/src/std/string.c index e90bd788..c24cc099 100644 --- a/Userspace/libc/src/std/string.c +++ b/Userspace/libc/src/std/string.c @@ -84,7 +84,15 @@ export int strcoll(const char *s1, const char *s2) } export int strcoll_l(const char *, const char *, locale_t); -export char *strcpy(char *restrict, const char *restrict); + +export char *strcpy(char *restrict s1, const char *restrict s2) +{ + char *dest = s1; + while (*s2) + *dest++ = *s2++; + *dest = '\0'; + return s1; +} export size_t strcspn(const char *s1, const char *s2) {