From a54c80d07bbaa8cb34dd5924d0926ac47e7deded Mon Sep 17 00:00:00 2001
From: dzwdz
Date: Tue, 27 Dec 2022 22:31:48 +0100
Subject: libc: fix strncmp

---
 src/user/lib/string/string.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

(limited to 'src/user/lib')

diff --git a/src/user/lib/string/string.c b/src/user/lib/string/string.c
index f141a3d..126d175 100644
--- a/src/user/lib/string/string.c
+++ b/src/user/lib/string/string.c
@@ -109,12 +109,11 @@ char *strtok_r(char *restrict s, const char *restrict sep, char **restrict state
 }
 
 int strncmp(const char *s1, const char *s2, size_t n) {
-	while (n-- & *s1 && *s1 == *s2) {
-		s1++; s2++;
+	for (size_t i = 0; i < n; i++) {
+		if (s1[i] < s2[i]) return -1;
+		if (s1[i] > s2[i]) return  1;
 	}
-	if (*s1 == *s2) return  0;
-	if (*s1 <  *s2) return -1;
-	else            return  1;
+	return 0;
 }
 
 int strcoll(const char *s1, const char *s2) {
-- 
cgit v1.2.3