From 62ba2a9ab01e5f2a9b1cd325af8d3112702b7713 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Mon, 15 Apr 2024 20:34:58 +0200 Subject: Bug fix and cleanup. --- kernel/libc/include/string.h | 1 - kernel/libc/string/copy.c | 9 +++++---- kernel/libc/string/strncpy.c | 11 ----------- 3 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 kernel/libc/string/strncpy.c (limited to 'kernel/libc') diff --git a/kernel/libc/include/string.h b/kernel/libc/include/string.h index 707d391..89ea5ab 100644 --- a/kernel/libc/include/string.h +++ b/kernel/libc/include/string.h @@ -13,7 +13,6 @@ int isequal(const char *s1, const char *s2); int isequal_n(const char *s1, const char *s2, u32 n); char *copy_and_allocate_string(const char *s); char *copy_and_allocate_user_string(const char *s); -char *strncpy(char *dest, const char *src, size_t n); size_t strlcpy(char *dst, const char *src, size_t dsize); char *strcat(char *s1, const char *s2); #endif diff --git a/kernel/libc/string/copy.c b/kernel/libc/string/copy.c index 11cd664..4acbbf4 100644 --- a/kernel/libc/string/copy.c +++ b/kernel/libc/string/copy.c @@ -4,12 +4,13 @@ #include char *copy_and_allocate_string(const char *s) { - size_t l = strlen(s); - char *r = kmalloc(l + 1); + size_t l = strlen(s) + 1; + char *r = kmalloc(l); if (!r) { return NULL; } - return strncpy(r, s, l); + memcpy(r, s, l); + return r; } char *copy_and_allocate_user_string(const char *s) { @@ -24,6 +25,6 @@ char *copy_and_allocate_user_string(const char *s) { if (!r) { return NULL; } - strlcpy(r, s, len); + memcpy(r, s, len+1); return r; } diff --git a/kernel/libc/string/strncpy.c b/kernel/libc/string/strncpy.c deleted file mode 100644 index a886895..0000000 --- a/kernel/libc/string/strncpy.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -// FIXME: Something is weird with this function -char *strncpy(char *dest, const char *src, size_t n) { - char *r = dest; - for (; n && (*dest = *src); n--, src++, dest++) - ; - *dest = '\0'; - return r; -} -- cgit v1.2.3