From 891f1010bbdc1351bda8d2a6139094a14bdfd5e1 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Sat, 24 Feb 2024 14:47:25 -0600 Subject: kernel: string: add a strcpy function Add an implmentation of strcpy. This function is used in several places in the kernel to copy strings between memory addresses. Signed-off-by: Danny Holman --- kernel/string.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'kernel/string.c') diff --git a/kernel/string.c b/kernel/string.c index 35dc16e..fa0fd3f 100644 --- a/kernel/string.c +++ b/kernel/string.c @@ -31,6 +31,14 @@ void* memcpy(void* __restrict dest, const void* __restrict src, size_t n) { return dest; } +char* strncpy(char* __restrict dest, const char* __restrict src, size_t n) { + for (int i = 0; i < n; i++) { + if (src[i] == '\0') + break; + dest[i] = src[i]; + } +} + char* strcpy(char* __restrict dest, const char* __restrict src) { if (strlen(src) > strlen(dest)) return NULL; -- cgit v1.2.3