krnl386: Avoid using toupperW().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-04-01 10:30:21 +02:00
parent 2ec3396122
commit 73dad192b4
3 changed files with 37 additions and 44 deletions

View File

@ -461,10 +461,13 @@ LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
UINT WINAPI GetTempDrive( BYTE ignored ) UINT WINAPI GetTempDrive( BYTE ignored )
{ {
WCHAR buffer[MAX_PATH]; WCHAR buffer[MAX_PATH];
BYTE ret; BYTE ret = 'C';
if (GetTempPathW( MAX_PATH, buffer )) ret = (BYTE)toupperW(buffer[0]); if (GetTempPathW( MAX_PATH, buffer ))
else ret = 'C'; {
ret = buffer[0];
if (ret >= 'a' && ret <= 'z') ret += 'A' - 'a';
}
return MAKELONG( ret | (':' << 8), 1 ); return MAKELONG( ret | (':' << 8), 1 );
} }

View File

@ -264,6 +264,13 @@ typedef struct
static int brk_flag; static int brk_flag;
static BYTE drive_number( WCHAR letter )
{
if (letter >= 'A' && letter <= 'Z') return letter - 'A';
if (letter >= 'a' && letter <= 'z') return letter - 'a';
return MAX_DOS_DRIVES;
}
/* Many calls translate a drive argument like this: /* Many calls translate a drive argument like this:
drive number (00h = default, 01h = A:, etc) drive number (00h = default, 01h = A:, etc)
@ -300,8 +307,7 @@ static BYTE INT21_GetCurrentDrive(void)
TRACE( "Failed to get current drive.\n" ); TRACE( "Failed to get current drive.\n" );
return MAX_DOS_DRIVES; return MAX_DOS_DRIVES;
} }
return drive_number( current_directory[0] );
return toupperW( current_directory[0] ) - 'A';
} }
@ -636,7 +642,7 @@ static BOOL INT21_GetCurrentDirectory( CONTEXT *context, BOOL islong )
if (!GetCurrentDirectoryW( MAX_PATH, pathW )) return FALSE; if (!GetCurrentDirectoryW( MAX_PATH, pathW )) return FALSE;
if (toupperW(pathW[0]) - 'A' != drive || pathW[1] != ':') if (drive_number( pathW[0] ) != drive || pathW[1] != ':')
{ {
/* cwd is not on the requested drive, get the environment string instead */ /* cwd is not on the requested drive, get the environment string instead */
@ -765,7 +771,7 @@ static BOOL INT21_SetCurrentDirectory( CONTEXT *context )
result = SetEnvironmentVariableW( env_var, dirW ); result = SetEnvironmentVariableW( env_var, dirW );
/* only set current directory if on the current drive */ /* only set current directory if on the current drive */
if (result && (toupperW(dirW[0]) - 'A' == drive)) result = SetCurrentDirectoryW( dirW ); if (result && (drive_number( dirW[0] ) == drive)) result = SetCurrentDirectoryW( dirW );
return result; return result;
} }
@ -3418,8 +3424,7 @@ static BOOL INT21_ToDosFCBFormat( LPCWSTR name, LPWSTR buffer )
break; break;
default: default:
if (strchrW( invalid_chars, *p )) return FALSE; if (strchrW( invalid_chars, *p )) return FALSE;
buffer[i] = toupperW(*p); buffer[i] = *p++;
p++;
break; break;
} }
} }
@ -3455,12 +3460,12 @@ static BOOL INT21_ToDosFCBFormat( LPCWSTR name, LPWSTR buffer )
break; break;
default: default:
if (strchrW( invalid_chars, *p )) return FALSE; if (strchrW( invalid_chars, *p )) return FALSE;
buffer[i] = toupperW(*p); buffer[i] = *p++;
p++;
break; break;
} }
} }
buffer[11] = '\0'; buffer[11] = '\0';
struprW( buffer );
/* at most 3 character of the extension are processed /* at most 3 character of the extension are processed
* is something behind this ? * is something behind this ?
@ -3514,7 +3519,7 @@ static BOOL INT21_FindFirst( CONTEXT *context )
/* we must have a fully qualified file name in dta->fullPath /* we must have a fully qualified file name in dta->fullPath
* (we could have a UNC path, but this would lead to some errors later on) * (we could have a UNC path, but this would lead to some errors later on)
*/ */
dta->drive = toupperW(dta->fullPath[0]) - 'A'; dta->drive = drive_number( dta->fullPath[0] );
dta->count = 0; dta->count = 0;
dta->search_attr = CL_reg(context); dta->search_attr = CL_reg(context);
return TRUE; return TRUE;

View File

@ -59,37 +59,22 @@ typedef struct {
} RELAY_Stack16; } RELAY_Stack16;
static const WCHAR **debug_relay_excludelist; static const char **debug_relay_excludelist;
static const WCHAR **debug_relay_includelist; static const char **debug_relay_includelist;
static const WCHAR **debug_snoop_excludelist; static const char **debug_snoop_excludelist;
static const WCHAR **debug_snoop_includelist; static const char **debug_snoop_includelist;
/* compare an ASCII and a Unicode string without depending on the current codepage */
static inline int strcmpiAW( const char *strA, const WCHAR *strW )
{
while (*strA && (toupperW((unsigned char)*strA) == toupperW(*strW))) { strA++; strW++; }
return toupperW((unsigned char)*strA) - toupperW(*strW);
}
/* compare an ASCII and a Unicode string without depending on the current codepage */
static inline int strncmpiAW( const char *strA, const WCHAR *strW, int n )
{
int ret = 0;
for ( ; n > 0; n--, strA++, strW++)
if ((ret = toupperW((unsigned char)*strA) - toupperW(*strW)) || !*strA) break;
return ret;
}
/*********************************************************************** /***********************************************************************
* build_list * build_list
* *
* Build a function list from a ';'-separated string. * Build a function list from a ';'-separated string.
*/ */
static const WCHAR **build_list( const WCHAR *buffer ) static const char **build_list( const WCHAR *buffer )
{ {
int count = 1; int count = 1;
const WCHAR *p = buffer; const WCHAR *p = buffer;
const WCHAR **ret; const char **ret;
while ((p = strchrW( p, ';' ))) while ((p = strchrW( p, ';' )))
{ {
@ -98,17 +83,17 @@ static const WCHAR **build_list( const WCHAR *buffer )
} }
/* allocate count+1 pointers, plus the space for a copy of the string */ /* allocate count+1 pointers, plus the space for a copy of the string */
if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, if ((ret = RtlAllocateHeap( GetProcessHeap(), 0,
(count+1) * sizeof(WCHAR*) + (strlenW(buffer)+1) * sizeof(WCHAR) ))) (count + 1) * sizeof(char *) + (strlenW(buffer) + 1) )))
{ {
WCHAR *str = (WCHAR *)(ret + count + 1); char *str = (char *)(ret + count + 1);
WCHAR *p = str; char *p = str;
strcpyW( str, buffer ); while ((*str++ = *buffer++));
count = 0; count = 0;
for (;;) for (;;)
{ {
ret[count++] = p; ret[count++] = p;
if (!(p = strchrW( p, ';' ))) break; if (!(p = strchr( p, ';' ))) break;
*p++ = 0; *p++ = 0;
} }
ret[count++] = NULL; ret[count++] = NULL;
@ -185,25 +170,25 @@ void RELAY16_InitDebugLists(void)
* *
* Check if a given module and function is in the list. * Check if a given module and function is in the list.
*/ */
static BOOL check_list( const char *module, int ordinal, const char *func, const WCHAR **list ) static BOOL check_list( const char *module, int ordinal, const char *func, const char **list )
{ {
char ord_str[10]; char ord_str[10];
sprintf( ord_str, "%d", ordinal ); sprintf( ord_str, "%d", ordinal );
for(; *list; list++) for(; *list; list++)
{ {
const WCHAR *p = strrchrW( *list, '.' ); const char *p = strrchr( *list, '.' );
if (p && p > *list) /* check module and function */ if (p && p > *list) /* check module and function */
{ {
int len = p - *list; int len = p - *list;
if (strncmpiAW( module, *list, len-1 ) || module[len]) continue; if (_strnicmp( module, *list, len-1 ) || module[len]) continue;
if (p[1] == '*' && !p[2]) return TRUE; if (p[1] == '*' && !p[2]) return TRUE;
if (!strcmpiAW( ord_str, p + 1 )) return TRUE; if (!strcmp( ord_str, p + 1 )) return TRUE;
if (func && !strcmpiAW( func, p + 1 )) return TRUE; if (func && !_strnicmp( func, p + 1, -1 )) return TRUE;
} }
else /* function only */ else /* function only */
{ {
if (func && !strcmpiAW( func, *list )) return TRUE; if (func && !_strnicmp( func, *list, -1 )) return TRUE;
} }
} }
return FALSE; return FALSE;