4 Commits

Author SHA1 Message Date
3e6f8d0072 Merge pull request #117 from gbowne1/klibc-strncpy
[klibc] implment strncpy function
2026-02-03 10:54:06 -08:00
Borna Šoštarić
bfc9911a85 add strcpy implementation 2026-01-28 21:55:01 +01:00
Borna Šoštarić
9d394d984b fix formatting in klibc/string.c 2026-01-28 21:54:28 +01:00
Borna Šoštarić
45abf9418b fix formatting in klibc/string.h 2026-01-28 21:53:55 +01:00
2 changed files with 48 additions and 31 deletions

View File

@@ -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

View File

@@ -105,3 +105,19 @@ 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;
}