String: strncmp, strncpy

This commit is contained in:
Imbus 2025-09-08 00:45:41 +02:00
parent 8316c9f6ae
commit e9f2eef252
2 changed files with 21 additions and 3 deletions

View file

@ -178,3 +178,20 @@ size_t strnlen(const char *s, size_t maxlen) {
}
return len;
}
int strncmp(const char *p, const char *q, u32 n) {
while (n > 0 && *p && *p == *q) n--, p++, q++;
if (n == 0)
return 0;
return (u8)*p - (u8)*q;
}
char *strncpy(char *s, const char *t, int n) {
char *os;
os = s;
while (n-- > 0 && (*s++ = *t++) != 0) {
}
while (n-- > 0) *s++ = 0;
return os;
}