From e06765ae0dbbc874ff9e04dbd0e7d82989048261 Mon Sep 17 00:00:00 2001 From: Gary Lin Date: Fri, 7 Apr 2017 17:14:09 +0800 Subject: Cryptlib: implement strcmp() and strcasecmp() strcmp() and strcasecmp() are widely used in openssl. Implement those two functions to eliminate the gcc warnings and the potential crash. Signed-off-by: Gary Lin --- Cryptlib/SysCall/BaseStrings.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Cryptlib/SysCall/BaseStrings.c') diff --git a/Cryptlib/SysCall/BaseStrings.c b/Cryptlib/SysCall/BaseStrings.c index 43875712..1844a657 100644 --- a/Cryptlib/SysCall/BaseStrings.c +++ b/Cryptlib/SysCall/BaseStrings.c @@ -64,4 +64,32 @@ AsciiStrSize(CHAR8 *string) return strlena(string) + 1; } +int +strcmp (const char *str1, const char *str2) +{ + return strcmpa((CHAR8 *)str1,(CHAR8 *)str2); +} + +inline static char +toupper (char c) +{ + return ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c); +} +/* Based on AsciiStriCmp() in edk2 MdePkg/Library/BaseLib/String.c */ +int +strcasecmp (const char *str1, const char *str2) +{ + char c1, c2; + + c1 = toupper (*str1); + c2 = toupper (*str2); + while ((*str1 != '\0') && (c1 == c2)) { + str1++; + str2++; + c1 = toupper (*str1); + c2 = toupper (*str2); + } + + return c1 - c2; +} -- cgit v1.2.3