From: Andrew Cooper Date: Tue, 2 Aug 2016 17:07:18 +0000 (+0100) Subject: Add an implementation of strcmp() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9f35dbe0;p=people%2Fliuw%2Fxtf.git Add an implementation of strcmp() Signed-off-by: Andrew Cooper --- diff --git a/common/libc/string.c b/common/libc/string.c index b134b6c..5e139f6 100644 --- a/common/libc/string.c +++ b/common/libc/string.c @@ -1,4 +1,4 @@ -#include +#include size_t strlen(const char *str) { @@ -20,6 +20,18 @@ size_t strnlen(const char *str, size_t max) return s - str; } +int strcmp(const char *_s1, const char *_s2) +{ + char s1, s2; + + do { + s1 = *_s1++; + s2 = *_s2++; + } while ( s1 && s1 == s2 ); + + return (s1 < s2) ? -1 : (s1 > s2); +} + 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 cf0aaf4..e699fe2 100644 --- a/include/xtf/libc.h +++ b/include/xtf/libc.h @@ -15,12 +15,14 @@ */ #define strlen(s) __builtin_strlen(s) +#define strcmp(s1, s2) __builtin_strcmp(s1, s2) #define memset(d, c, n) __builtin_memset(d, c, n) #define memcpy(d, s, n) __builtin_memcpy(d, s, n) #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n) size_t strlen(const char *str); size_t strnlen(const char *str, size_t max); +int strcmp(const char *s1, const char *s2); void *memset(void *s, int c, size_t n); void *memcpy(void *dst, const void *src, size_t n); int memcmp(const void *s1, const void *s2, size_t n);