From bfa068df8834f3171cc728016bcf9eb9e9ca09bd Mon Sep 17 00:00:00 2001
From: jD91mZM2 <me@krake.one>
Date: Wed, 17 Oct 2018 21:26:16 +0200
Subject: [PATCH] Fix strcasecmp return value

---
 src/header/strings/mod.rs |  5 +++--
 tests/strings.c           | 14 +++++++++-----
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/header/strings/mod.rs b/src/header/strings/mod.rs
index a0afc460d..2b7888f42 100644
--- a/src/header/strings/mod.rs
+++ b/src/header/strings/mod.rs
@@ -77,8 +77,9 @@ pub unsafe extern "C" fn strncasecmp(
     mut n: size_t,
 ) -> c_int {
     while n > 0 && (*first != 0 || *second != 0) {
-        if *first & !32 != *second & !32 {
-            return -1;
+        let cmp = (*first & !32) as c_int - (*second & !32) as c_int;
+        if cmp != 0 {
+            return cmp;
         }
 
         first = first.offset(1);
diff --git a/tests/strings.c b/tests/strings.c
index 1e4685488..ecc098a02 100644
--- a/tests/strings.c
+++ b/tests/strings.c
@@ -12,11 +12,15 @@ int main() {
 
     assert(!strcasecmp("hi", new));
     assert(strcasecmp("he", new));
-    assert(!strcasecmp("hello", "HEllO"));
-    assert(strcasecmp("hello", "HEllOo"));
-    assert(!strncasecmp("hello", "Hello World", 5));
-    assert(!strncasecmp("FLOOR0_1", "FLOOR0_1FLOOR4_1", 8));
-    assert(strncasecmp("FL00RO_1", "FLOOR0_1FLOOR4_1", 8));
+
+    assert(strcasecmp("hello", "HEllO") == 0);
+    assert(strcasecmp("hello", "HEllOo") < 0);
+    assert(strcasecmp("5", "5") == 0);
+    assert(strcasecmp("5", "4") > 0);
+    assert(strcasecmp("5", "6") < 0);
+    assert(strncasecmp("hello", "Hello World", 5) == 0);
+    assert(strncasecmp("FLOOR0_1", "FLOOR0_1FLOOR4_1", 8) == 0);
+    assert(strncasecmp("FL00RO_1", "FLOOR0_1FLOOR4_1", 8) < 0);
 
     bzero(new, 1);
     assert(*new == 0);
-- 
GitLab