msvcrt: Reimplement strcmp/strncmp to get consistent return values.

The system functions may not always return -1 or 1.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-10-31 09:35:40 +01:00
parent 79052f5890
commit 97425bd963
4 changed files with 16 additions and 7 deletions

View File

@ -2075,7 +2075,7 @@ int CDECL MSVCRT_type_info_compare(const type_info140 *l, const type_info140 *r)
int ret;
if (l == r) ret = 0;
else ret = strcmp(l->mangled + 1, r->mangled + 1);
else ret = MSVCRT_strcmp(l->mangled + 1, r->mangled + 1);
TRACE("(%p %p) returning %d\n", l, r, ret);
return ret;
}

View File

@ -118,7 +118,7 @@ static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char*
static inline int u_strcmp( const unsigned char *s1, const unsigned char *s2 )
{
return strcmp( (const char*)s1, (const char*)s2 );
return MSVCRT_strcmp( (const char*)s1, (const char*)s2 );
}
static inline int u_strcasecmp( const unsigned char *s1, const unsigned char *s2 )
@ -128,7 +128,7 @@ static inline int u_strcasecmp( const unsigned char *s1, const unsigned char *s2
static inline int u_strncmp( const unsigned char *s1, const unsigned char *s2, MSVCRT_size_t len )
{
return strncmp( (const char*)s1, (const char*)s2, len );
return MSVCRT_strncmp( (const char*)s1, (const char*)s2, len );
}
static inline int u_strncasecmp( const unsigned char *s1, const unsigned char *s2, MSVCRT_size_t len )

View File

@ -1176,6 +1176,8 @@ int __cdecl MSVCRT__stricmp(const char*, const char*);
int __cdecl MSVCRT__strnicmp(const char*, const char*, MSVCRT_size_t);
int __cdecl MSVCRT__strnicoll_l(const char*, const char*, MSVCRT_size_t, MSVCRT__locale_t);
int __cdecl MSVCRT__strncoll_l(const char*, const char*, MSVCRT_size_t, MSVCRT__locale_t);
int __cdecl MSVCRT_strncmp(const char*, const char*, MSVCRT_size_t);
int __cdecl MSVCRT_strcmp(const char*, const char*);
char* __cdecl MSVCRT_strstr(const char*, const char*);
unsigned int __cdecl MSVCRT__get_output_format(void);
char* __cdecl MSVCRT_strtok_s(char*, const char*, char**);

View File

@ -616,7 +616,7 @@ int CDECL MSVCRT_strcoll_l( const char* str1, const char* str2, MSVCRT__locale_t
locinfo = locale->locinfo;
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
return strcmp(str1, str2);
return MSVCRT_strcmp(str1, str2);
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0, str1, -1, str2, -1)-CSTR_EQUAL;
}
@ -667,7 +667,7 @@ int CDECL MSVCRT__strncoll_l( const char* str1, const char* str2, MSVCRT_size_t
locinfo = locale->locinfo;
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE])
return strncmp(str1, str2, count);
return MSVCRT_strncmp(str1, str2, count);
return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0,
str1, MSVCRT_strnlen(str1, count),
str2, MSVCRT_strnlen(str2, count))-CSTR_EQUAL;
@ -1943,7 +1943,10 @@ void* __cdecl MSVCRT_memchr(const void *ptr, int c, MSVCRT_size_t n)
*/
int __cdecl MSVCRT_strcmp(const char *str1, const char *str2)
{
return strcmp(str1, str2);
while (*str1 && *str1 == *str2) { str1++; str2++; }
if (*str1 > *str2) return 1;
if (*str1 < *str2) return -1;
return 0;
}
/*********************************************************************
@ -1951,7 +1954,11 @@ int __cdecl MSVCRT_strcmp(const char *str1, const char *str2)
*/
int __cdecl MSVCRT_strncmp(const char *str1, const char *str2, MSVCRT_size_t len)
{
return strncmp(str1, str2, len);
if (!len) return 0;
while (--len && *str1 && *str1 == *str2) { str1++; str2++; }
if (*str1 > *str2) return 1;
if (*str1 < *str2) return -1;
return 0;
}
/*********************************************************************