Added ASCII-only version of toupper, tolower, strcasecmp and the like

for file and module I/O.
This commit is contained in:
Aric Stewart 2000-12-03 03:14:29 +00:00 committed by Alexandre Julliard
parent 719c3a84cc
commit e4d09327ef
8 changed files with 85 additions and 194 deletions

View File

@ -79,7 +79,7 @@ static const DOS_DEVICE DOSFS_Devices[] =
};
#define GET_DRIVE(path) \
(((path)[1] == ':') ? toupper((path)[0]) - 'A' : DOSFS_CurDrive)
(((path)[1] == ':') ? FILE_toupper((path)[0]) - 'A' : DOSFS_CurDrive)
/* Directory info for DOSFS_ReadDir */
typedef struct
@ -196,7 +196,7 @@ BOOL DOSFS_ToDosFCBFormat( LPCSTR name, LPSTR buffer )
break;
default:
if (strchr( invalid_chars, *p )) return FALSE;
buffer[i] = toupper(*p);
buffer[i] = FILE_toupper(*p);
p++;
break;
}
@ -233,7 +233,7 @@ BOOL DOSFS_ToDosFCBFormat( LPCSTR name, LPSTR buffer )
break;
default:
if (strchr( invalid_chars, *p )) return FALSE;
buffer[i] = toupper(*p);
buffer[i] = FILE_toupper(*p);
p++;
break;
}
@ -318,7 +318,7 @@ static int DOSFS_MatchLong( const char *mask, const char *name,
/* skip to the next match after the joker(s) */
if (case_sensitive) while (*name && (*name != *mask)) name++;
else while (*name && (toupper(*name) != toupper(*mask))) name++;
else while (*name && (FILE_toupper(*name) != FILE_toupper(*mask))) name++;
if (!*name) break;
next_to_retry = name;
@ -332,7 +332,7 @@ static int DOSFS_MatchLong( const char *mask, const char *name,
}
else
{
if (toupper(*mask) != toupper(*name)) mismatch = 1;
if (FILE_toupper(*mask) != FILE_toupper(*name)) mismatch = 1;
}
if (!mismatch)
{
@ -500,13 +500,13 @@ static void DOSFS_Hash( LPCSTR name, LPSTR buffer, BOOL dir_format,
/* Simply copy the name, converting to uppercase */
for (dst = buffer; !IS_END_OF_NAME(*name) && (*name != '.'); name++)
*dst++ = toupper(*name);
*dst++ = FILE_toupper(*name);
if (*name == '.')
{
if (dir_format) dst = buffer + 8;
else *dst++ = '.';
for (name++; !IS_END_OF_NAME(*name); name++)
*dst++ = toupper(*name);
*dst++ = FILE_toupper(*name);
}
if (!dir_format) *dst = '\0';
return;
@ -518,8 +518,8 @@ static void DOSFS_Hash( LPCSTR name, LPSTR buffer, BOOL dir_format,
if (ignore_case)
{
for (p = name, hash = 0xbeef; !IS_END_OF_NAME(p[1]); p++)
hash = (hash<<3) ^ (hash>>5) ^ tolower(*p) ^ (tolower(p[1]) << 8);
hash = (hash<<3) ^ (hash>>5) ^ tolower(*p); /* Last character*/
hash = (hash<<3) ^ (hash>>5) ^ FILE_tolower(*p) ^ (FILE_tolower(p[1]) << 8);
hash = (hash<<3) ^ (hash>>5) ^ FILE_tolower(*p); /* Last character*/
}
else
{
@ -538,7 +538,7 @@ static void DOSFS_Hash( LPCSTR name, LPSTR buffer, BOOL dir_format,
for (i = 4, p = name, dst = buffer; i > 0; i--, p++)
{
if (IS_END_OF_NAME(*p) || (p == ext)) break;
*dst++ = strchr( invalid_chars, *p ) ? '_' : toupper(*p);
*dst++ = strchr( invalid_chars, *p ) ? '_' : FILE_toupper(*p);
}
/* Pad to 5 chars with '~' */
while (i-- >= 0) *dst++ = '~';
@ -553,7 +553,7 @@ static void DOSFS_Hash( LPCSTR name, LPSTR buffer, BOOL dir_format,
{
if (!dir_format) *dst++ = '.';
for (i = 3, ext++; (i > 0) && !IS_END_OF_NAME(*ext); i--, ext++)
*dst++ = strchr( invalid_chars, *ext ) ? '_' : toupper(*ext);
*dst++ = strchr( invalid_chars, *ext ) ? '_' : FILE_toupper(*ext);
}
if (!dir_format) *dst = '\0';
}
@ -608,7 +608,7 @@ BOOL DOSFS_FindUnixName( LPCSTR path, LPCSTR name, LPSTR long_buf,
}
else
{
if (!strncasecmp( long_name, name, len )) break;
if (!FILE_strncasecmp( long_name, name, len )) break;
}
}
if (dos_name[0])
@ -659,7 +659,7 @@ const DOS_DEVICE *DOSFS_GetDevice( const char *name )
for (i = 0; i < sizeof(DOSFS_Devices)/sizeof(DOSFS_Devices[0]); i++)
{
const char *dev = DOSFS_Devices[i].name;
if (!strncasecmp( dev, name, strlen(dev) ))
if (!FILE_strncasecmp( dev, name, strlen(dev) ))
{
p = name + strlen( dev );
if (!*p || (*p == '.')) return &DOSFS_Devices[i];
@ -744,7 +744,7 @@ HFILE DOSFS_OpenDevice( const char *name, DWORD access )
for (i = 0; i < sizeof(DOSFS_Devices)/sizeof(DOSFS_Devices[0]); i++)
{
const char *dev = DOSFS_Devices[i].name;
if (!strncasecmp( dev, name, strlen(dev) ))
if (!FILE_strncasecmp( dev, name, strlen(dev) ))
{
p = name + strlen( dev );
if (!*p || (*p == '.')) {
@ -802,7 +802,7 @@ static int DOSFS_GetPathDrive( const char **name )
if (*p && (p[1] == ':'))
{
drive = toupper(*p) - 'A';
drive = FILE_toupper(*p) - 'A';
*name += 2;
}
else if (*p == '/') /* Absolute Unix path? */
@ -925,11 +925,11 @@ BOOL DOSFS_GetFullName( LPCSTR name, BOOL check_last, DOS_FULL_NAME *full )
(p_s < full->short_name + sizeof(full->short_name) - 1) &&
(p_l < full->long_name + sizeof(full->long_name) - 1))
{
*p_s++ = tolower(*name);
*p_s++ = FILE_tolower(*name);
/* If the drive is case-sensitive we want to create new */
/* files in lower-case otherwise we can't reopen them */
/* under the same short name. */
if (flags & DRIVE_CASE_SENSITIVE) *p_l++ = tolower(*name);
if (flags & DRIVE_CASE_SENSITIVE) *p_l++ = FILE_tolower(*name);
else *p_l++ = *name;
name++;
}
@ -1197,7 +1197,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCSTR name, DWORD len, LPSTR result,
/*absolute path given */
{
lstrcpynA(full_name.short_name,name,MAX_PATHNAME_LEN);
drive = (int)toupper(name[0]) - 'A';
drive = (int)FILE_toupper(name[0]) - 'A';
}
else
{
@ -1211,7 +1211,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCSTR name, DWORD len, LPSTR result,
return 0;
}
/* find path that drive letter substitutes*/
drive = (int)toupper(full_name.short_name[0]) -0x41;
drive = (int)FILE_toupper(full_name.short_name[0]) -0x41;
root= DRIVE_GetRoot(drive);
if (!root)
{
@ -1279,7 +1279,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCSTR name, DWORD len, LPSTR result,
memmove(p+1,p+3,strlen(p+3)+1);
}
if (!(DRIVE_GetFlags(drive) & DRIVE_CASE_PRESERVING))
_strupr( full_name.short_name );
for (p = full_name.short_name; *p; p++) *p = FILE_toupper(*p);
namelen=strlen(full_name.short_name);
if (!strcmp(full_name.short_name+namelen-3,"\\.."))
{
@ -1596,7 +1596,7 @@ HANDLE WINAPI FindFirstFileExA(
info->short_mask = NULL;
info->attr = 0xff;
if (lpFileName[0] && (lpFileName[1] == ':'))
info->drive = toupper(*lpFileName) - 'A';
info->drive = FILE_toupper(*lpFileName) - 'A';
else info->drive = DRIVE_GetCurrentDrive();
info->cur_pos = 0;
@ -2256,7 +2256,7 @@ HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATAA *data )
*(info->long_mask++) = '\0';
info->short_mask = NULL;
info->attr = 0xff;
if (path[0] && (path[1] == ':')) info->drive = toupper(*path) - 'A';
if (path[0] && (path[1] == ':')) info->drive = FILE_toupper(*path) - 'A';
else info->drive = DRIVE_GetCurrentDrive();
info->cur_pos = 0;

View File

@ -86,161 +86,35 @@ static void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing )
}
#if 0
/***********************************************************************
* FILE_ShareDeny
* FILE_strcasecmp
*
* PARAMS
* oldmode[I] mode how file was first opened
* mode[I] mode how the file should get opened
* RETURNS
* TRUE: deny open
* FALSE: allow open
*
* Look what we have to do with the given SHARE modes
*
* Ralph Brown's interrupt list gives following explication, I guess
* the same holds for Windows, DENY ALL should be OF_SHARE_COMPAT
*
* FIXME: Validate this function
========from Ralph Brown's list =========
(Table 0750)
Values of DOS file sharing behavior:
| Second and subsequent Opens
First |Compat Deny Deny Deny Deny
Open | All Write Read None
|R W RW R W RW R W RW R W RW R W RW
- - - - -| - - - - - - - - - - - - - - - - -
Compat R |Y Y Y N N N 1 N N N N N 1 N N
W |Y Y Y N N N N N N N N N N N N
RW|Y Y Y N N N N N N N N N N N N
- - - - -|
Deny R |C C C N N N N N N N N N N N N
All W |C C C N N N N N N N N N N N N
RW|C C C N N N N N N N N N N N N
- - - - -|
Deny R |2 C C N N N Y N N N N N Y N N
Write W |C C C N N N N N N Y N N Y N N
RW|C C C N N N N N N N N N Y N N
- - - - -|
Deny R |C C C N N N N Y N N N N N Y N
Read W |C C C N N N N N N N Y N N Y N
RW|C C C N N N N N N N N N N Y N
- - - - -|
Deny R |2 C C N N N Y Y Y N N N Y Y Y
None W |C C C N N N N N N Y Y Y Y Y Y
RW|C C C N N N N N N N N N Y Y Y
Legend: Y = open succeeds, N = open fails with error code 05h
C = open fails, INT 24 generated
1 = open succeeds if file read-only, else fails with error code
2 = open succeeds if file read-only, else fails with INT 24
========end of description from Ralph Brown's List =====
For every "Y" in the table we return FALSE
For every "N" we set the DOS_ERROR and return TRUE
For all other cases we barf,set the DOS_ERROR and return TRUE
* locale-independent case conversion for file I/O
*/
static BOOL FILE_ShareDeny( int mode, int oldmode)
int FILE_strcasecmp( const char *str1, const char *str2 )
{
int oldsharemode = oldmode & 0x70;
int sharemode = mode & 0x70;
int oldopenmode = oldmode & 3;
int openmode = mode & 3;
switch (oldsharemode)
for (;;)
{
case OF_SHARE_COMPAT:
if (sharemode == OF_SHARE_COMPAT) return FALSE;
if (openmode == OF_READ) goto test_ro_err05;
goto fail_error05;
case OF_SHARE_EXCLUSIVE:
if (sharemode == OF_SHARE_COMPAT) goto fail_int24;
goto fail_error05;
case OF_SHARE_DENY_WRITE:
if (openmode != OF_READ)
{
if (sharemode == OF_SHARE_COMPAT) goto fail_int24;
goto fail_error05;
}
switch (sharemode)
{
case OF_SHARE_COMPAT:
if (oldopenmode == OF_READ) goto test_ro_int24;
goto fail_int24;
case OF_SHARE_DENY_NONE:
return FALSE;
case OF_SHARE_DENY_WRITE:
if (oldopenmode == OF_READ) return FALSE;
case OF_SHARE_DENY_READ:
if (oldopenmode == OF_WRITE) return FALSE;
case OF_SHARE_EXCLUSIVE:
default:
goto fail_error05;
}
break;
case OF_SHARE_DENY_READ:
if (openmode != OF_WRITE)
{
if (sharemode == OF_SHARE_COMPAT) goto fail_int24;
goto fail_error05;
}
switch (sharemode)
{
case OF_SHARE_COMPAT:
goto fail_int24;
case OF_SHARE_DENY_NONE:
return FALSE;
case OF_SHARE_DENY_WRITE:
if (oldopenmode == OF_READ) return FALSE;
case OF_SHARE_DENY_READ:
if (oldopenmode == OF_WRITE) return FALSE;
case OF_SHARE_EXCLUSIVE:
default:
goto fail_error05;
}
break;
case OF_SHARE_DENY_NONE:
switch (sharemode)
{
case OF_SHARE_COMPAT:
goto fail_int24;
case OF_SHARE_DENY_NONE:
return FALSE;
case OF_SHARE_DENY_WRITE:
if (oldopenmode == OF_READ) return FALSE;
case OF_SHARE_DENY_READ:
if (oldopenmode == OF_WRITE) return FALSE;
case OF_SHARE_EXCLUSIVE:
default:
goto fail_error05;
}
default:
ERR("unknown mode\n");
int ret = FILE_toupper(*str1) - FILE_toupper(*str2);
if (ret || !*str1) return ret;
str1++;
str2++;
}
ERR("shouldn't happen\n");
ERR("Please report to bon@elektron.ikp.physik.tu-darmstadt.de\n");
return TRUE;
test_ro_int24:
if (oldmode == OF_READ)
return FALSE;
/* Fall through */
fail_int24:
FIXME("generate INT24 missing\n");
/* Is this the right error? */
SetLastError( ERROR_ACCESS_DENIED );
return TRUE;
test_ro_err05:
if (oldmode == OF_READ)
return FALSE;
/* fall through */
fail_error05:
TRACE("Access Denied, oldmode 0x%02x mode 0x%02x\n",oldmode,mode);
SetLastError( ERROR_ACCESS_DENIED );
return TRUE;
}
#endif
/***********************************************************************
* FILE_strncasecmp
*
* locale-independent case conversion for file I/O
*/
int FILE_strncasecmp( const char *str1, const char *str2, int len )
{
int ret = 0;
for ( ; len > 0; len--, str1++, str2++)
if ((ret = FILE_toupper(*str1) - FILE_toupper(*str2)) || !*str1) break;
return ret;
}
/***********************************************************************

View File

@ -13,6 +13,7 @@
#include "builtin16.h"
#include "global.h"
#include "heap.h"
#include "file.h"
#include "module.h"
#include "miscemu.h"
#include "stackframe.h"
@ -127,7 +128,7 @@ HMODULE16 BUILTIN_LoadModule( LPCSTR name )
const BUILTIN16_DESCRIPTOR *descr = builtin_dlls[i];
NE_MODULE *pModule = (NE_MODULE *)descr->module_start;
OFSTRUCT *pOfs = (OFSTRUCT *)((LPBYTE)pModule + pModule->fileinfo);
if (!strcasecmp( pOfs->szPathName, dllname ))
if (!FILE_strcasecmp( pOfs->szPathName, dllname ))
return BUILTIN_DoLoadModule16( descr );
}
@ -138,7 +139,7 @@ HMODULE16 BUILTIN_LoadModule( LPCSTR name )
const BUILTIN16_DESCRIPTOR *descr = builtin_dlls[i];
NE_MODULE *pModule = (NE_MODULE *)descr->module_start;
OFSTRUCT *pOfs = (OFSTRUCT *)((LPBYTE)pModule + pModule->fileinfo);
if (!strcasecmp( pOfs->szPathName, dllname ))
if (!FILE_strcasecmp( pOfs->szPathName, dllname ))
return BUILTIN_DoLoadModule16( descr );
}
ERR( "loaded .so but dll %s still not found\n", dllname );

View File

@ -30,8 +30,21 @@ typedef struct
int flags;
} DOS_DEVICE;
/* locale-independent case conversion */
inline static char FILE_tolower( char c )
{
if (c >= 'A' && c <= 'Z') c += 32;
return c;
}
inline static char FILE_toupper( char c )
{
if (c >= 'a' && c <= 'z') c -= 32;
return c;
}
/* files/file.c */
extern int FILE_strcasecmp( const char *str1, const char *str2 );
extern int FILE_strncasecmp( const char *str1, const char *str2, int len );
extern void FILE_SetDosError(void);
extern HFILE FILE_DupUnixHandle( int fd, DWORD access );
extern int FILE_GetUnixHandle( HANDLE handle, DWORD access );

View File

@ -19,6 +19,7 @@
#include "snoop.h"
#include "process.h"
#include "heap.h"
#include "file.h"
#include "module.h"
#include "debugtools.h"
#include "winerror.h"
@ -133,7 +134,7 @@ WINE_MODREF *ELF_LoadLibraryExA( LPCSTR libname, DWORD flags)
s = strchr(x,'.');
if (s) {
while (s) {
if (!strcasecmp(s,".dll")) {
if (!FILE_strcasecmp(s,".dll")) {
strcpy(s+1,UNIX_DLL_ENDING);
break;
}

View File

@ -13,6 +13,7 @@
#include "options.h"
#include "loadorder.h"
#include "heap.h"
#include "file.h"
#include "module.h"
#include "elfdll.h"
#include "debugtools.h"
@ -98,7 +99,8 @@ static const struct tagDllPair {
*/
static int cmp_sort_func(const void *s1, const void *s2)
{
return strcasecmp(((module_loadorder_t *)s1)->modulename, ((module_loadorder_t *)s2)->modulename);
return FILE_strcasecmp(((module_loadorder_t *)s1)->modulename,
((module_loadorder_t *)s2)->modulename);
}
@ -262,7 +264,8 @@ static BOOL AddLoadOrderSet(char *key, char *order, BOOL override)
char *ext = strrchr(cptr, '.');
if(ext)
{
if(strlen(ext) == 4 && (!strcasecmp(ext, ".dll") || !strcasecmp(ext, ".exe")))
if(strlen(ext) == 4 &&
(!FILE_strcasecmp(ext, ".dll") || !FILE_strcasecmp(ext, ".exe")))
MESSAGE("Warning: Loadorder override '%s' contains an extension and might not be found during lookup\n", cptr);
}
@ -504,7 +507,7 @@ module_loadorder_t *MODULE_GetLoadOrder(const char *path, BOOL win32 )
/* Strip path information for 16 bit modules or if the module
resides in the system directory */
if ( !win32 || !strncasecmp ( sysdir, path, strlen (sysdir) ) )
if ( !win32 || !FILE_strncasecmp ( sysdir, path, strlen (sysdir) ) )
{
cptr = strrchr(path, '\\');
@ -532,7 +535,7 @@ module_loadorder_t *MODULE_GetLoadOrder(const char *path, BOOL win32 )
}
strcpy(fname, name);
if(len >= 4 && (!strcasecmp(fname+len-4, ".dll") || !strcasecmp(fname+len-4, ".exe")))
if(len >= 4 && (!FILE_strcasecmp(fname+len-4, ".dll") || !FILE_strcasecmp(fname+len-4, ".exe")))
fname[len-4] = '\0';
lo.modulename = fname;

View File

@ -14,6 +14,7 @@
#include "wine/winbase16.h"
#include "winerror.h"
#include "heap.h"
#include "file.h"
#include "process.h"
#include "selectors.h"
#include "debugtools.h"
@ -433,13 +434,13 @@ WINE_MODREF *MODULE_FindModule(
for ( wm = PROCESS_Current()->modref_list; wm; wm = wm->next )
{
if ( !strcasecmp( dllname, wm->modname ) )
if ( !FILE_strcasecmp( dllname, wm->modname ) )
break;
if ( !strcasecmp( dllname, wm->filename ) )
if ( !FILE_strcasecmp( dllname, wm->filename ) )
break;
if ( !strcasecmp( dllname, wm->short_modname ) )
if ( !FILE_strcasecmp( dllname, wm->short_modname ) )
break;
if ( !strcasecmp( dllname, wm->short_filename ) )
if ( !FILE_strcasecmp( dllname, wm->short_filename ) )
break;
}
@ -631,13 +632,13 @@ static BOOL MODULE_GetBinaryType( HANDLE hfile, LPCSTR filename, LPDWORD lpBinar
ptr = strrchr( filename, '.' );
if ( ptr && !strchr( ptr, '\\' ) && !strchr( ptr, '/' ) )
{
if ( !strcasecmp( ptr, ".COM" ) )
if ( !FILE_strcasecmp( ptr, ".COM" ) )
{
*lpBinaryType = SCS_DOS_BINARY;
return TRUE;
}
if ( !strcasecmp( ptr, ".PIF" ) )
if ( !FILE_strcasecmp( ptr, ".PIF" ) )
{
*lpBinaryType = SCS_PIF_BINARY;
return TRUE;
@ -1304,7 +1305,7 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
if the library name does not contain a path and can not be found, assume the
system directory is meant */
if ( ! strncasecmp ( filename, libname, strlen ( filename ) ))
if ( ! FILE_strncasecmp ( filename, libname, strlen ( filename ) ))
strcpy ( filename, libname );
else
{

View File

@ -252,8 +252,8 @@ WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
/* Now copy and uppercase the string */
strcpy( buffer, name );
_strupr( buffer );
len = strlen( buffer );
for (cpnt = buffer; *cpnt; cpnt++) *cpnt = FILE_toupper(*cpnt);
len = cpnt - buffer;
/* First search the resident names */
@ -1466,8 +1466,7 @@ HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
/* If uppercased 'name' matches exactly the module name of a module:
* Return its handle
*/
for (s = tmpstr; *s; s++)
*s = toupper(*s);
for (s = tmpstr; *s; s++) *s = FILE_toupper(*s);
for (hModule = hFirstModule; hModule ; hModule = pModule->next)
{
@ -1482,7 +1481,7 @@ HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
* 'i' compare is just a quickfix until the loader handles that
* correctly. -MM 990705
*/
if ((*name_table == len) && !strncasecmp(tmpstr, name_table+1, len))
if ((*name_table == len) && !FILE_strncasecmp(tmpstr, name_table+1, len))
return hModule;
}
@ -1521,7 +1520,7 @@ HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
loadedfn--;
}
/* case insensitive compare ... */
if (!strcasecmp(loadedfn, s))
if (!FILE_strcasecmp(loadedfn, s))
return hModule;
}
@ -1529,7 +1528,7 @@ HMODULE16 WINAPI GetModuleHandle16( LPCSTR name )
* matches the base filename of the module filename of some 32-bit module:
* Return the corresponding 16-bit dummy module handle.
*/
if (len >= 4 && !strcasecmp(name+len-4, ".EXE"))
if (len >= 4 && !FILE_strcasecmp(name+len-4, ".EXE"))
{
HMODULE hModule = GetModuleHandleA( name );
if ( hModule )
@ -1596,10 +1595,9 @@ static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
loadedfn--;
}
/* case insensitive compare ... */
if (!strcasecmp(loadedfn, s))
if (!FILE_strcasecmp(loadedfn, s))
return hModule;
}
/* If basename (without ext) matches the module name of a module:
* Return its handle.
*/
@ -1614,7 +1612,7 @@ static HMODULE16 NE_GetModuleByFilename( LPCSTR name )
if (pModule->flags & NE_FFLAGS_WIN32) continue;
name_table = (BYTE *)pModule + pModule->name_table;
if ((*name_table == len) && !strncasecmp(s, name_table+1, len))
if ((*name_table == len) && !FILE_strncasecmp(s, name_table+1, len))
return hModule;
}