From: Pawel Wieczorkiewicz Date: Thu, 23 Apr 2020 10:19:18 +0000 (+0000) Subject: libc: add strncmp() function X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2a8859e87761a0efc119778e094f203dc2ea487a;p=people%2Fandrewcoop%2Fxen-test-framework.git libc: add strncmp() function Signed-off-by: Pawel Wieczorkiewicz [Fix style] Signed-off-by: Andrew Cooper --- diff --git a/common/libc/string.c b/common/libc/string.c index 5c25e27..8ddceab 100644 --- a/common/libc/string.c +++ b/common/libc/string.c @@ -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; diff --git a/include/xtf/libc.h b/include/xtf/libc.h index f24a631..86d2abd 100644 --- a/include/xtf/libc.h +++ b/include/xtf/libc.h @@ -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)