mirror of https://github.com/acidanthera/audk.git
StdLib: Fix strcmp so that comparisons are case sensitive. Simplified code for strcasecmp.
Signed-off-by: darylm503 Reviewed-by: jljusten Reviewed-by: geekboy15a git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12620 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
52cb711dab
commit
eaa52ade0f
|
@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t n)
|
||||||
**/
|
**/
|
||||||
int strcmp(const char *s1, const char *s2)
|
int strcmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
return (int)AsciiStriCmp( s1, s2);
|
return (int)AsciiStrCmp( s1, s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The strcoll function compares the string pointed to by s1 to the string
|
/** The strcoll function compares the string pointed to by s1 to the string
|
||||||
|
@ -72,33 +72,33 @@ int strncmp(const char *s1, const char *s2, size_t n)
|
||||||
return (int)AsciiStrnCmp( s1, s2, n);
|
return (int)AsciiStrnCmp( s1, s2, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The strxfrm function transforms the string pointed to by s2 and places the
|
/** The strxfrm function transforms the string pointed to by Src and places the
|
||||||
resulting string into the array pointed to by s1. The transformation is
|
resulting string into the array pointed to by Dest. The transformation is
|
||||||
such that if the strcmp function is applied to two transformed strings, it
|
such that if the strcmp function is applied to two transformed strings, it
|
||||||
returns a value greater than, equal to, or less than zero, corresponding to
|
returns a value greater than, equal to, or less than zero, corresponding to
|
||||||
the result of the strcoll function applied to the same two original
|
the result of the strcoll function applied to the same two original
|
||||||
strings. No more than n characters are placed into the resulting array
|
strings. No more than Len characters are placed into the resulting array
|
||||||
pointed to by s1, including the terminating null character. If n is zero,
|
pointed to by Dest, including the terminating null character. If Len is zero,
|
||||||
s1 is permitted to be a null pointer. If copying takes place between
|
Dest is permitted to be a null pointer. If copying takes place between
|
||||||
objects that overlap, the behavior is undefined.
|
objects that overlap, the behavior is undefined.
|
||||||
|
|
||||||
@return The strxfrm function returns the length of the transformed string
|
@return The strxfrm function returns the length of the transformed string
|
||||||
(not including the terminating null character). If the value
|
(not including the terminating null character). If the value
|
||||||
returned is n or more, the contents of the array pointed to by s1
|
returned is Len or more, the contents of the array pointed to by Dest
|
||||||
are indeterminate.
|
are indeterminate.
|
||||||
**/
|
**/
|
||||||
size_t strxfrm(char * __restrict s1, const char * __restrict s2, size_t n)
|
size_t strxfrm(char * __restrict Dest, const char * __restrict Src, size_t Len)
|
||||||
{
|
{
|
||||||
size_t srclen, copysize;
|
size_t srclen, copysize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since locales are unimplemented, this is just a copy.
|
* Since locales are unimplemented, this is just a copy.
|
||||||
*/
|
*/
|
||||||
srclen = strlen(s2);
|
srclen = strlen(Src);
|
||||||
if (n != 0) {
|
if (Len != 0) {
|
||||||
copysize = srclen < n ? srclen : n - 1;
|
copysize = srclen < Len ? srclen : Len - 1;
|
||||||
(void)memcpy(s1, s2, copysize);
|
(void)memcpy(Dest, Src, copysize);
|
||||||
s1[copysize] = 0;
|
Dest[copysize] = 0;
|
||||||
}
|
}
|
||||||
return (srclen);
|
return (srclen);
|
||||||
}
|
}
|
||||||
|
@ -107,17 +107,5 @@ size_t strxfrm(char * __restrict s1, const char * __restrict s2, size_t n)
|
||||||
int
|
int
|
||||||
strcasecmp(const char *s1, const char *s2)
|
strcasecmp(const char *s1, const char *s2)
|
||||||
{
|
{
|
||||||
const unsigned char *us1 = (const unsigned char *)s1,
|
return (int)AsciiStriCmp( s1, s2);
|
||||||
*us2 = (const unsigned char *)s2;
|
|
||||||
int Difference;
|
|
||||||
|
|
||||||
while ( 0 == ( Difference = tolower(*us1) - tolower(*us2))) {
|
|
||||||
if (*us1 == 0) {
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
us1 += 1;
|
|
||||||
us2 += 1;
|
|
||||||
}
|
|
||||||
return Difference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue