Commit 97425bd9 authored by Alexandre Julliard's avatar Alexandre Julliard

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

The system functions may not always return -1 or 1. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 79052f58
...@@ -2075,7 +2075,7 @@ int CDECL MSVCRT_type_info_compare(const type_info140 *l, const type_info140 *r) ...@@ -2075,7 +2075,7 @@ int CDECL MSVCRT_type_info_compare(const type_info140 *l, const type_info140 *r)
int ret; int ret;
if (l == r) ret = 0; 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); TRACE("(%p %p) returning %d\n", l, r, ret);
return ret; return ret;
} }
......
...@@ -118,7 +118,7 @@ static inline unsigned char* u_strncat( unsigned char* dst, const unsigned char* ...@@ -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 ) 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 ) 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 ...@@ -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 ) 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 ) static inline int u_strncasecmp( const unsigned char *s1, const unsigned char *s2, MSVCRT_size_t len )
......
...@@ -1176,6 +1176,8 @@ int __cdecl MSVCRT__stricmp(const char*, const char*); ...@@ -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__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__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__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*); char* __cdecl MSVCRT_strstr(const char*, const char*);
unsigned int __cdecl MSVCRT__get_output_format(void); unsigned int __cdecl MSVCRT__get_output_format(void);
char* __cdecl MSVCRT_strtok_s(char*, const char*, char**); char* __cdecl MSVCRT_strtok_s(char*, const char*, char**);
......
...@@ -616,7 +616,7 @@ int CDECL MSVCRT_strcoll_l( const char* str1, const char* str2, MSVCRT__locale_t ...@@ -616,7 +616,7 @@ int CDECL MSVCRT_strcoll_l( const char* str1, const char* str2, MSVCRT__locale_t
locinfo = locale->locinfo; locinfo = locale->locinfo;
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) 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; 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 ...@@ -667,7 +667,7 @@ int CDECL MSVCRT__strncoll_l( const char* str1, const char* str2, MSVCRT_size_t
locinfo = locale->locinfo; locinfo = locale->locinfo;
if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) 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, return CompareStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE], 0,
str1, MSVCRT_strnlen(str1, count), str1, MSVCRT_strnlen(str1, count),
str2, MSVCRT_strnlen(str2, count))-CSTR_EQUAL; str2, MSVCRT_strnlen(str2, count))-CSTR_EQUAL;
...@@ -1943,7 +1943,10 @@ void* __cdecl MSVCRT_memchr(const void *ptr, int c, MSVCRT_size_t n) ...@@ -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) 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) ...@@ -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) 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;
} }
/********************************************************************* /*********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment