Browse Source

[Pal/lib] Add strcmp() function

Thomas Knauth 4 years ago
parent
commit
de5efcd53d
3 changed files with 23 additions and 6 deletions
  1. 1 0
      Pal/lib/api.h
  2. 22 0
      Pal/lib/string/strcmp.c
  3. 0 6
      Pal/regression/normalize_path.c

+ 1 - 0
Pal/lib/api.h

@@ -123,6 +123,7 @@ typedef ptrdiff_t ssize_t;
 /* Libc String functions string.h/stdlib.h */
 size_t strnlen (const char *str, size_t maxlen);
 size_t strlen (const char *str);
+int strcmp(const char* a, const char* b);
 
 long strtol (const char *s, char **endptr, int base);
 int atoi (const char *nptr);

+ 22 - 0
Pal/lib/string/strcmp.c

@@ -0,0 +1,22 @@
+#include "api.h"
+
+/* Copyright © 2005-2014 Rich Felker, et al. */
+
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+
+/* musl 1.1.24 */
+
+int strcmp(const char* l, const char* r) {
+    for (; *l == *r && *l; l++, r++)
+        ;
+    return *(unsigned char*)l - *(unsigned char*)r;
+}

+ 0 - 6
Pal/regression/normalize_path.c

@@ -3,12 +3,6 @@
 #include "pal_defs.h"
 #include "pal_error.h"
 
-static int strcmp(const char* a, const char* b) {
-    for (; *a && *b && *a == *b; a++, b++)
-        ;
-    return *a - *b;
-}
-
 static const char* get_norm_path_cases[][2] = {
     {"/", "/"},
     {"/a/b/c", "/a/b/c"},