summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-10-27 17:41:55 +1100
committerDamien George <damien@micropython.org>2023-10-30 11:10:02 +1100
commite910533012b7298f5c11622d501878c678dbf45e (patch)
treed0d590554d97527548946c2682562b5b3e82409c
parent78f4f30cb1aadbb46ad39220de5369e72c093509 (diff)
bare-arm/lib: Add minimal strncmp implementation.
Required by upcoming qstr sorting. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
-rw-r--r--ports/bare-arm/lib.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/ports/bare-arm/lib.c b/ports/bare-arm/lib.c
index 6ef450bea..61d3be64e 100644
--- a/ports/bare-arm/lib.c
+++ b/ports/bare-arm/lib.c
@@ -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) {