Alexandre Julliard : krnl386: Avoid using toupperW().
Alexandre Julliard
julliard at winehq.org
Wed Apr 1 15:50:58 CDT 2020
Module: wine
Branch: master
Commit: 73dad192b49880c9754d46ae84aa9f4a97dd2ea8
URL: https://source.winehq.org/git/wine.git/?a=commit;h=73dad192b49880c9754d46ae84aa9f4a97dd2ea8
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Apr 1 10:30:21 2020 +0200
krnl386: Avoid using toupperW().
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/krnl386.exe16/file.c | 9 ++++++---
dlls/krnl386.exe16/int21.c | 23 +++++++++++++---------
dlls/krnl386.exe16/relay.c | 49 ++++++++++++++++------------------------------
3 files changed, 37 insertions(+), 44 deletions(-)
diff --git a/dlls/krnl386.exe16/file.c b/dlls/krnl386.exe16/file.c
index 4e7f7c4b33..e44455a021 100644
--- a/dlls/krnl386.exe16/file.c
+++ b/dlls/krnl386.exe16/file.c
@@ -461,10 +461,13 @@ LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
UINT WINAPI GetTempDrive( BYTE ignored )
{
WCHAR buffer[MAX_PATH];
- BYTE ret;
+ BYTE ret = 'C';
- if (GetTempPathW( MAX_PATH, buffer )) ret = (BYTE)toupperW(buffer[0]);
- else ret = 'C';
+ if (GetTempPathW( MAX_PATH, buffer ))
+ {
+ ret = buffer[0];
+ if (ret >= 'a' && ret <= 'z') ret += 'A' - 'a';
+ }
return MAKELONG( ret | (':' << 8), 1 );
}
diff --git a/dlls/krnl386.exe16/int21.c b/dlls/krnl386.exe16/int21.c
index 04ae9fe8a8..feab712af0 100644
--- a/dlls/krnl386.exe16/int21.c
+++ b/dlls/krnl386.exe16/int21.c
@@ -264,6 +264,13 @@ typedef struct
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:
drive number (00h = default, 01h = A:, etc)
@@ -300,8 +307,7 @@ static BYTE INT21_GetCurrentDrive(void)
TRACE( "Failed to get current drive.\n" );
return MAX_DOS_DRIVES;
}
-
- return toupperW( current_directory[0] ) - 'A';
+ return drive_number( current_directory[0] );
}
@@ -636,7 +642,7 @@ static BOOL INT21_GetCurrentDirectory( CONTEXT *context, BOOL islong )
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 */
@@ -765,7 +771,7 @@ static BOOL INT21_SetCurrentDirectory( CONTEXT *context )
result = SetEnvironmentVariableW( env_var, dirW );
/* 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;
}
@@ -3418,8 +3424,7 @@ static BOOL INT21_ToDosFCBFormat( LPCWSTR name, LPWSTR buffer )
break;
default:
if (strchrW( invalid_chars, *p )) return FALSE;
- buffer[i] = toupperW(*p);
- p++;
+ buffer[i] = *p++;
break;
}
}
@@ -3455,12 +3460,12 @@ static BOOL INT21_ToDosFCBFormat( LPCWSTR name, LPWSTR buffer )
break;
default:
if (strchrW( invalid_chars, *p )) return FALSE;
- buffer[i] = toupperW(*p);
- p++;
+ buffer[i] = *p++;
break;
}
}
buffer[11] = '\0';
+ struprW( buffer );
/* at most 3 character of the extension are processed
* 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 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->search_attr = CL_reg(context);
return TRUE;
diff --git a/dlls/krnl386.exe16/relay.c b/dlls/krnl386.exe16/relay.c
index a47e85126e..837f389230 100644
--- a/dlls/krnl386.exe16/relay.c
+++ b/dlls/krnl386.exe16/relay.c
@@ -59,37 +59,22 @@ typedef struct {
} RELAY_Stack16;
-static const WCHAR **debug_relay_excludelist;
-static const WCHAR **debug_relay_includelist;
-static const WCHAR **debug_snoop_excludelist;
-static const WCHAR **debug_snoop_includelist;
+static const char **debug_relay_excludelist;
+static const char **debug_relay_includelist;
+static const char **debug_snoop_excludelist;
+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 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;
const WCHAR *p = buffer;
- const WCHAR **ret;
+ const char **ret;
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 */
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);
- WCHAR *p = str;
+ char *str = (char *)(ret + count + 1);
+ char *p = str;
- strcpyW( str, buffer );
+ while ((*str++ = *buffer++));
count = 0;
for (;;)
{
ret[count++] = p;
- if (!(p = strchrW( p, ';' ))) break;
+ if (!(p = strchr( p, ';' ))) break;
*p++ = 0;
}
ret[count++] = NULL;
@@ -185,25 +170,25 @@ void RELAY16_InitDebugLists(void)
*
* 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];
sprintf( ord_str, "%d", ordinal );
for(; *list; list++)
{
- const WCHAR *p = strrchrW( *list, '.' );
+ const char *p = strrchr( *list, '.' );
if (p && p > *list) /* check module and function */
{
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 (!strcmpiAW( ord_str, p + 1 )) return TRUE;
- if (func && !strcmpiAW( func, p + 1 )) return TRUE;
+ if (!strcmp( ord_str, p + 1 )) return TRUE;
+ if (func && !_strnicmp( func, p + 1, -1 )) return TRUE;
}
else /* function only */
{
- if (func && !strcmpiAW( func, *list )) return TRUE;
+ if (func && !_strnicmp( func, *list, -1 )) return TRUE;
}
}
return FALSE;
More information about the wine-cvs
mailing list