bare-arm/lib: Add minimal strncmp implementation.

Required by upcoming qstr sorting.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-10-27 17:41:55 +11:00 committed by Damien George
parent 78f4f30cb1
commit e910533012
1 changed files with 9 additions and 2 deletions

View File

@ -109,16 +109,23 @@ char *strchr(const char *s, int c) {
return NULL;
}
int strcmp(const char *s1, const char *s2) {
while (*s1 && *s2) {
int strncmp(const char *s1, const char *s2, size_t n) {
while (*s1 && *s2 && n-- > 0) {
int c = *s1++ - *s2++;
if (c) {
return c;
}
}
if (n == 0) {
return 0;
}
return *s1 - *s2;
}
int strcmp(const char *s1, const char *s2) {
return strncmp(s1, s2, 0x7fffffff);
}
size_t strlen(const char *s) {
const char *ss = s;
while (*ss) {