From bfc9911a85c2b9a7b8381e36e86035c58e2b0dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20=C5=A0o=C5=A1tari=C4=87?= Date: Wed, 28 Jan 2026 21:55:01 +0100 Subject: [PATCH] add strcpy implementation --- klibc/include/string.h | 1 + klibc/src/string.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/klibc/include/string.h b/klibc/include/string.h index ab46b28..843ed88 100644 --- a/klibc/include/string.h +++ b/klibc/include/string.h @@ -10,5 +10,6 @@ extern void *memset(void *dst, int c, size_t n); extern size_t strlen(const char *s); extern int strcmp(const char *s1, const char *s2); +extern char *strncpy(char *dst, const char *src, size_t n); #endif // CLASSICOS_KLIBC_STRING_H diff --git a/klibc/src/string.c b/klibc/src/string.c index f5a4c58..21495ce 100644 --- a/klibc/src/string.c +++ b/klibc/src/string.c @@ -106,3 +106,18 @@ int strcmp(const char *s1, const char *s2) { return d; } +char *strncpy(char *dst, const char *src, size_t n) { + char *q = dst; + const char *p = src; + char ch; + + while (n) { + n--; + *q++ = ch = *p++; + if (!ch) break; + } + + memset(q, 0, n); + + return dst; +}