]> xenbits.xensource.com Git - people/aperard/xtf.git/commitdiff
libc: add strncmp() function
authorPawel Wieczorkiewicz <wipawel@amazon.de>
Thu, 23 Apr 2020 10:19:18 +0000 (10:19 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 5 Jun 2020 19:50:54 +0000 (20:50 +0100)
Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
[Fix style]
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/libc/string.c
include/xtf/libc.h

index 5c25e2728971f63bd8712aed9d4ebdba4315af9c..8ddceab7419d51f387d27d791367e15d0a2965a2 100644 (file)
@@ -56,6 +56,15 @@ int (strcmp)(const char *_s1, const char *_s2)
     return (s1 < s2) ? -1 : (s1 > s2);
 }
 
+int (strncmp)(const char *_s1, const char *_s2, size_t n)
+{
+    for ( size_t i = 0; i < n; i++)
+        if ( _s1[i] != _s2[i] )
+            return _s1[i] - _s2[i];
+
+    return 0;
+}
+
 void *(memset)(void *s, int c, size_t n)
 {
     char *p = s;
index f24a631f35e8f1a31aa9ce8a8a75528c3b6f9d70..86d2abdf2c6a81bf2663450852748e8afb48c57d 100644 (file)
@@ -26,6 +26,9 @@ char *strncpy(char *dst, const char *src, size_t n);
 int strcmp(const char *s1, const char *s2);
 #define strcmp(s1, s2)              __builtin_strcmp(s1, s2)
 
+int strncmp(const char *s1, const char *s2, size_t n);
+#define strncmp(s1, s2, n)          __builtin_strncmp(s1, s2, n)
+
 void *memset(void *s, int c, size_t n);
 #define memset(d, c, n)             __builtin_memset(d, c, n)