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 <glin@suse.com>
This commit is contained in:
Gary Lin 2017-04-07 17:14:09 +08:00 committed by Peter Jones
parent ae75df6232
commit 9bc647e2b2
2 changed files with 30 additions and 1 deletions

View File

@ -374,7 +374,6 @@ extern FILE *stdout;
#define strncpy(strDest,strSource,count) AsciiStrnCpy(strDest,strSource,(UINTN)count)
#define strcat(strDest,strSource) AsciiStrCat(strDest,strSource)
#define strchr(str,ch) (char *)(ScanMem8((CHAR8 *)str,AsciiStrSize((CHAR8 *)str),ch))
#define strcmp(string1,string2) strcmpa((CHAR8 *)string1,(CHAR8 *)string2)
#define strncmp(string1,string2,count) (int)(AsciiStrnCmp(string1,string2,(UINTN)(count)))
#define localtime(timer) NULL
#define assert(expression)

View File

@ -93,3 +93,33 @@ AsciiStrDecimalToUintn(const char *String)
return Result;
}
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;
}