Commit 49a0224f authored by Alexandre Julliard's avatar Alexandre Julliard

Get rid of the drive codepages and use CP_UNIXCP instead.

parent f95be92d
......@@ -41,7 +41,6 @@
#include "winreg.h"
#include "winternl.h"
#include "wine/winbase16.h"
#include "drive.h"
#include "file.h"
#include "heap.h"
#include "wine/unicode.h"
......@@ -458,7 +457,6 @@ static BOOL PROFILE_FlushFile(void)
if (!CurProfile->changed || !CurProfile->dos_name) return TRUE;
if (!(unix_name = CurProfile->unix_name) || !(file = fopen(unix_name, "w")))
{
int drive = toupperW(CurProfile->dos_name[0]) - 'A';
WCHAR *name, *name_lwr;
/* Try to create it in $HOME/.wine */
/* FIXME: this will need a more general solution */
......@@ -472,7 +470,7 @@ static BOOL PROFILE_FlushFile(void)
name_lwr = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(WCHAR));
strcpyW(name_lwr, name);
strlwrW(name_lwr);
WideCharToMultiByte(DRIVE_GetCodepage(drive), 0, name_lwr, -1,
WideCharToMultiByte(CP_UNIXCP, 0, name_lwr, -1,
p, sizeof(buffer) - strlen(buffer), NULL, NULL);
HeapFree(GetProcessHeap(), 0, name_lwr);
......@@ -623,7 +621,7 @@ static BOOL PROFILE_Open( LPCWSTR filename )
name_lwr = HeapAlloc(GetProcessHeap(), 0, (strlenW(name) + 1) * sizeof(WCHAR));
strcpyW(name_lwr, name);
strlwrW(name_lwr);
WideCharToMultiByte(DRIVE_GetCodepage(full_name.drive), 0, name_lwr, -1,
WideCharToMultiByte(CP_UNIXCP, 0, name_lwr, -1,
p, sizeof(buffer) - strlen(buffer), NULL, NULL);
HeapFree(GetProcessHeap(), 0, name_lwr);
......
......@@ -156,7 +156,7 @@ int DIR_Init(void)
else
{
WCHAR szdrive[3]={drive+'A',':',0};
MultiByteToWideChar(DRIVE_GetCodepage(drive), 0, cwd, -1, longpath, MAX_PATHNAME_LEN);
MultiByteToWideChar(CP_UNIXCP, 0, cwd, -1, longpath, MAX_PATHNAME_LEN);
DRIVE_SetCurrentDrive( drive );
DRIVE_Chdir( drive, longpath );
if(GetDriveTypeW(szdrive)==DRIVE_CDROM)
......@@ -938,8 +938,7 @@ TRACE("drive %c: root %s\n", 'A' + full_name.drive, DRIVE_GetRoot(full_name.driv
LPWSTR p;
if (buflen > 3)
{
MultiByteToWideChar(DRIVE_GetCodepage(full_name.drive), 0,
res, -1, buffer + 3, buflen - 3);
MultiByteToWideChar(CP_UNIXCP, 0, res, -1, buffer + 3, buflen - 3);
buffer[buflen - 1] = 0;
}
for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
......
......@@ -482,7 +482,7 @@ static BOOL DOSFS_AddDirEntry(DOS_DIR **dir, LPCWSTR name, LPCWSTR dosname)
/***********************************************************************
* DOSFS_OpenDir_VFAT
*/
static BOOL DOSFS_OpenDir_VFAT(UINT codepage, DOS_DIR **dir, const char *unix_path)
static BOOL DOSFS_OpenDir_VFAT(DOS_DIR **dir, const char *unix_path)
{
#ifdef VFAT_IOCTL_READDIR_BOTH
KERNEL_DIRENT de[2];
......@@ -504,13 +504,13 @@ static BOOL DOSFS_OpenDir_VFAT(UINT codepage, DOS_DIR **dir, const char *unix_pa
break;
if (!de[0].d_reclen)
break;
MultiByteToWideChar(codepage, 0, de[0].d_name, -1, long_name, MAX_PATH);
MultiByteToWideChar(CP_UNIXCP, 0, de[0].d_name, -1, long_name, MAX_PATH);
if (!DOSFS_ToDosFCBFormat( long_name, short_name ))
short_name[0] = '\0';
if (de[1].d_name[0])
MultiByteToWideChar(codepage, 0, de[1].d_name, -1, long_name, MAX_PATH);
MultiByteToWideChar(CP_UNIXCP, 0, de[1].d_name, -1, long_name, MAX_PATH);
else
MultiByteToWideChar(codepage, 0, de[0].d_name, -1, long_name, MAX_PATH);
MultiByteToWideChar(CP_UNIXCP, 0, de[0].d_name, -1, long_name, MAX_PATH);
r = DOSFS_AddDirEntry(dir, long_name, short_name );
if(!r)
break;
......@@ -533,7 +533,7 @@ static BOOL DOSFS_OpenDir_VFAT(UINT codepage, DOS_DIR **dir, const char *unix_pa
*
* Now use the standard opendir/readdir interface
*/
static BOOL DOSFS_OpenDir_Normal( UINT codepage, DOS_DIR **dir, const char *unix_path )
static BOOL DOSFS_OpenDir_Normal( DOS_DIR **dir, const char *unix_path )
{
DIR *unixdir = opendir( unix_path );
BOOL r = TRUE;
......@@ -548,7 +548,7 @@ static BOOL DOSFS_OpenDir_Normal( UINT codepage, DOS_DIR **dir, const char *unix
if(!de)
break;
MultiByteToWideChar(codepage, 0, de->d_name, -1, long_name, MAX_PATH);
MultiByteToWideChar(CP_UNIXCP, 0, de->d_name, -1, long_name, MAX_PATH);
r = DOSFS_AddDirEntry(dir, long_name, empty_strW);
if(!r)
break;
......@@ -562,7 +562,7 @@ static BOOL DOSFS_OpenDir_Normal( UINT codepage, DOS_DIR **dir, const char *unix
/***********************************************************************
* DOSFS_OpenDir
*/
static DOS_DIR *DOSFS_OpenDir( UINT codepage, const char *unix_path )
static DOS_DIR *DOSFS_OpenDir( const char *unix_path )
{
const int init_size = 0x100;
DOS_DIR *dir = HeapAlloc( GetProcessHeap(), 0, sizeof(*dir) + init_size*sizeof (WCHAR));
......@@ -582,10 +582,10 @@ static DOS_DIR *DOSFS_OpenDir( UINT codepage, const char *unix_path )
directory and mask in several other places */
if (!*unix_path) unix_path = "/";
r = DOSFS_OpenDir_VFAT( codepage, &dir, unix_path);
r = DOSFS_OpenDir_VFAT( &dir, unix_path);
if(!r)
r = DOSFS_OpenDir_Normal( codepage, &dir, unix_path);
r = DOSFS_OpenDir_Normal( &dir, unix_path);
if(!r)
{
......@@ -768,7 +768,7 @@ BOOL DOSFS_FindUnixName( const DOS_FULL_NAME *path, LPCWSTR name, char *long_buf
if (!DOSFS_ToDosFCBFormat( name, dos_name )) dos_name[0] = '\0';
if (!(dir = DOSFS_OpenDir( DRIVE_GetCodepage(path->drive), path->long_name )))
if (!(dir = DOSFS_OpenDir( path->long_name )))
{
WARN("(%s,%s): can't open dir: %s\n",
path->long_name, debugstr_w(name), strerror(errno) );
......@@ -802,8 +802,7 @@ BOOL DOSFS_FindUnixName( const DOS_FULL_NAME *path, LPCWSTR name, char *long_buf
}
if (ret)
{
if (long_buf) WideCharToMultiByte(DRIVE_GetCodepage(path->drive), 0,
long_name, -1, long_buf, long_len, NULL, NULL);
if (long_buf) WideCharToMultiByte(CP_UNIXCP, 0, long_name, -1, long_buf, long_len, NULL, NULL);
if (short_buf)
{
if (short_name)
......@@ -1052,7 +1051,7 @@ static int DOSFS_GetPathDrive( LPCWSTR *name )
BOOL DOSFS_GetFullName( LPCWSTR name, BOOL check_last, DOS_FULL_NAME *full )
{
BOOL found;
UINT flags, codepage;
UINT flags;
char *p_l, *root;
LPWSTR p_s;
static const WCHAR driveA_rootW[] = {'A',':','\\',0};
......@@ -1068,7 +1067,6 @@ BOOL DOSFS_GetFullName( LPCWSTR name, BOOL check_last, DOS_FULL_NAME *full )
if ((full->drive = DOSFS_GetPathDrive( &name )) == -1) return FALSE;
flags = DRIVE_GetFlags( full->drive );
codepage = DRIVE_GetCodepage(full->drive);
lstrcpynA( full->long_name, DRIVE_GetRoot( full->drive ),
sizeof(full->long_name) );
......@@ -1156,7 +1154,7 @@ BOOL DOSFS_GetFullName( LPCWSTR name, BOOL check_last, DOS_FULL_NAME *full )
/* under the same short name. */
if (flags & DRIVE_CASE_SENSITIVE) wch = tolowerW(*name);
else wch = *name;
p_l += WideCharToMultiByte(codepage, 0, &wch, 1, p_l, 2, NULL, NULL);
p_l += WideCharToMultiByte(CP_UNIXCP, 0, &wch, 1, p_l, 2, NULL, NULL);
name++;
}
/* Ignore trailing dots and spaces */
......@@ -1362,7 +1360,6 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen
const char *root;
LPWSTR p;
int drive;
UINT codepage;
DWORD ret, len = 0;
if (!shortpath) {
......@@ -1387,9 +1384,8 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen
root = full_name.long_name;
drive = DRIVE_FindDriveRoot(&root);
codepage = DRIVE_GetCodepage(drive);
ret = MultiByteToWideChar(codepage, 0, root, -1, NULL, 0);
ret = MultiByteToWideChar(CP_UNIXCP, 0, root, -1, NULL, 0);
ret += 3; /* A:\ */
/* reproduce terminating slash */
if (ret > 4) /* if not drive root */
......@@ -1403,7 +1399,7 @@ DWORD WINAPI GetLongPathNameW( LPCWSTR shortpath, LPWSTR longpath, DWORD longlen
{
longpath[0] = 'A' + drive;
longpath[1] = ':';
MultiByteToWideChar(codepage, 0, root, -1, longpath + 2, longlen - 2);
MultiByteToWideChar(CP_UNIXCP, 0, root, -1, longpath + 2, longlen - 2);
for (p = longpath; *p; p++) if (*p == '/') *p = '\\';
if (len)
{
......@@ -1541,8 +1537,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCWSTR name, DWORD len, LPWSTR result )
p_l = full_name.long_name + strlen(root);
}
/* append long name (= unix name) to drive */
MultiByteToWideChar(DRIVE_GetCodepage(drive), 0, p_l, -1,
full_name.short_name + 2, MAX_PATHNAME_LEN - 3);
MultiByteToWideChar(CP_UNIXCP, 0, p_l, -1, full_name.short_name + 2, MAX_PATHNAME_LEN - 3);
/* append name to treat */
namelen= strlenW(full_name.short_name);
p = (LPWSTR)name;
......@@ -1850,7 +1845,7 @@ static int DOSFS_FindNextEx( FIND_FIRST_INFO *info, WIN32_FIND_DATAW *entry )
}
/* Check the file attributes */
WideCharToMultiByte(DRIVE_GetCodepage(info->drive), 0, long_name, -1,
WideCharToMultiByte(CP_UNIXCP, 0, long_name, -1,
p, sizeof(buffer) - (int)(p - buffer), NULL, NULL);
if (!FILE_Stat( buffer, &fileinfo, &is_symlink ))
{
......@@ -1937,7 +1932,7 @@ int DOSFS_FindNext( const char *path, const char *short_mask,
info.attr = attr;
info.drive = drive;
info.cur_pos = 0;
info.u.dos_dir = DOSFS_OpenDir( DRIVE_GetCodepage(drive), info.path );
info.u.dos_dir = DOSFS_OpenDir( info.path );
}
else
{
......@@ -2012,7 +2007,6 @@ HANDLE WINAPI FindFirstFileExW(
WIN32_FIND_DATAW * data = (WIN32_FIND_DATAW *) lpFindFileData;
char *p;
INT long_mask_len;
UINT codepage;
data->dwReserved0 = data->dwReserved1 = 0x0;
if (lpFileName[0] == '\\' && lpFileName[1] == '\\')
......@@ -2048,19 +2042,18 @@ HANDLE WINAPI FindFirstFileExW(
info->path = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
strcpy( info->path, full_name.long_name );
codepage = DRIVE_GetCodepage(full_name.drive);
p = strrchr( info->path, '/' );
*p++ = '\0';
long_mask_len = MultiByteToWideChar(codepage, 0, p, -1, NULL, 0);
long_mask_len = MultiByteToWideChar(CP_UNIXCP, 0, p, -1, NULL, 0);
info->long_mask = HeapAlloc( GetProcessHeap(), 0, long_mask_len * sizeof(WCHAR) );
MultiByteToWideChar(codepage, 0, p, -1, info->long_mask, long_mask_len);
MultiByteToWideChar(CP_UNIXCP, 0, p, -1, info->long_mask, long_mask_len);
info->short_mask = NULL;
info->attr = 0xff;
info->drive = full_name.drive;
info->cur_pos = 0;
info->u.dos_dir = DOSFS_OpenDir( codepage, info->path );
info->u.dos_dir = DOSFS_OpenDir( info->path );
}
if (!FindNextFileW( (HANDLE) info, data ))
{
......
......@@ -90,7 +90,6 @@ typedef struct
DWORD serial_conf; /* drive serial number as cfg'd in wine config */
UINT type; /* drive type */
UINT flags; /* drive flags */
UINT codepage; /* drive code page */
dev_t dev; /* unix device number */
ino_t ino; /* unix inode number */
} DOSDRIVE;
......@@ -199,7 +198,6 @@ int DRIVE_Init(void)
UNICODE_STRING nameW;
static const WCHAR PathW[] = {'P','a','t','h',0};
static const WCHAR CodepageW[] = {'C','o','d','e','p','a','g','e',0};
static const WCHAR LabelW[] = {'L','a','b','e','l',0};
static const WCHAR SerialW[] = {'S','e','r','i','a','l',0};
static const WCHAR TypeW[] = {'T','y','p','e',0};
......@@ -223,14 +221,6 @@ int DRIVE_Init(void)
nameW.Buffer[(nameW.Length / sizeof(WCHAR)) - 1] = 'A' + i;
if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) continue;
/* Get the code page number */
RtlInitUnicodeString( &nameW, CodepageW );
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
{
WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
drive->codepage = strtolW( data, NULL, 10 );
}
/* Get the root path */
RtlInitUnicodeString( &nameW, PathW );
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
......@@ -243,19 +233,19 @@ int DRIVE_Init(void)
if (path[0] == '/')
{
len = WideCharToMultiByte(drive->codepage, 0, path, -1, NULL, 0, NULL, NULL);
len = WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL);
drive->root = HeapAlloc(GetProcessHeap(), 0, len);
WideCharToMultiByte(drive->codepage, 0, path, -1, drive->root, len, NULL, NULL);
WideCharToMultiByte(CP_UNIXCP, 0, path, -1, drive->root, len, NULL, NULL);
}
else
{
/* relative paths are relative to config dir */
const char *config = wine_get_config_dir();
len = strlen(config);
len += WideCharToMultiByte(drive->codepage, 0, path, -1, NULL, 0, NULL, NULL) + 2;
len += WideCharToMultiByte(CP_UNIXCP, 0, path, -1, NULL, 0, NULL, NULL) + 2;
drive->root = HeapAlloc( GetProcessHeap(), 0, len );
len -= sprintf( drive->root, "%s/", config );
WideCharToMultiByte(drive->codepage, 0, path, -1,
WideCharToMultiByte(CP_UNIXCP, 0, path, -1,
drive->root + strlen(drive->root), len, NULL, NULL);
}
......@@ -329,9 +319,9 @@ int DRIVE_Init(void)
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
{
WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
len = WideCharToMultiByte(drive->codepage, 0, data, -1, NULL, 0, NULL, NULL);
len = WideCharToMultiByte(CP_UNIXCP, 0, data, -1, NULL, 0, NULL, NULL);
drive->device = HeapAlloc(GetProcessHeap(), 0, len);
WideCharToMultiByte(drive->codepage, 0, data, -1, drive->device, len, NULL, NULL);
WideCharToMultiByte(CP_UNIXCP, 0, data, -1, drive->device, len, NULL, NULL);
RtlInitUnicodeString( &nameW, ReadVolInfoW );
if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
......@@ -366,10 +356,10 @@ int DRIVE_Init(void)
count++;
TRACE("Drive %c: path=%s type=%s label=%s serial=%08lx "
"flags=%08x codepage=%u dev=%x ino=%x\n",
"flags=%08x dev=%x ino=%x\n",
'A' + i, drive->root, debugstr_w(DRIVE_Types[drive->type]),
debugstr_w(drive->label_conf), drive->serial_conf, drive->flags,
drive->codepage, (int)drive->dev, (int)drive->ino );
(int)drive->dev, (int)drive->ino );
}
next:
......@@ -479,9 +469,8 @@ int DRIVE_FindDriveRoot( const char **path )
struct stat st;
strcpy( buffer, *path );
while ((p = strchr( buffer, '\\' )) != NULL)
*p = '/';
len = strlen(buffer);
for (p = buffer; *p; p++) if (*p == '\\') *p = '/';
len = p - buffer;
/* strip off trailing slashes */
while (len > 1 && buffer[len - 1] == '/') buffer[--len] = 0;
......@@ -541,49 +530,38 @@ int DRIVE_FindDriveRootW( LPCWSTR *path )
struct stat st;
strcpyW( buffer, *path );
while ((p = strchrW( buffer, '\\' )) != NULL)
*p = '/';
len = strlenW(buffer);
for (p = buffer; *p; p++) if (*p == '\\') *p = '/';
len = p - buffer;
/* strip off trailing slashes */
while (len > 1 && buffer[len - 1] == '/') buffer[--len] = 0;
for (;;)
{
int codepage = -1;
char buffA[MAX_PATHNAME_LEN];
/* Find the drive */
for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
WideCharToMultiByte( CP_UNIXCP, 0, buffer, -1, buffA, sizeof(buffA), NULL, NULL );
if (stat( buffA, &st ) == 0 && S_ISDIR( st.st_mode ))
{
char buffA[MAX_PATHNAME_LEN];
if (!DOSDrives[drive].root ||
(DOSDrives[drive].flags & DRIVE_DISABLED))
continue;
if (codepage != DOSDrives[drive].codepage)
/* Find the drive */
for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
{
WideCharToMultiByte( DOSDrives[drive].codepage, 0, buffer, -1,
buffA, sizeof(buffA), NULL, NULL );
if (stat( buffA, &st ) == -1 || !S_ISDIR( st.st_mode ))
{
codepage = -1;
if (!DOSDrives[drive].root ||
(DOSDrives[drive].flags & DRIVE_DISABLED))
continue;
}
codepage = DOSDrives[drive].codepage;
}
if ((DOSDrives[drive].dev == st.st_dev) &&
(DOSDrives[drive].ino == st.st_ino))
{
static const WCHAR rootW[] = {'\\',0};
if (len == 1) len = 0; /* preserve root slash in returned path */
TRACE( "%s -> drive %c:, root=%s, name=%s\n",
debugstr_w(*path), 'A' + drive, debugstr_w(buffer), debugstr_w(*path + len));
*path += len;
if (!**path) *path = rootW;
return drive;
if ((DOSDrives[drive].dev == st.st_dev) &&
(DOSDrives[drive].ino == st.st_ino))
{
static const WCHAR rootW[] = {'\\',0};
if (len == 1) len = 0; /* preserve root slash in returned path */
TRACE( "%s -> drive %c:, root=%s, name=%s\n",
debugstr_w(*path), 'A' + drive, debugstr_w(buffer), debugstr_w(*path + len));
*path += len;
if (!**path) *path = rootW;
return drive;
}
}
}
if (len <= 1) return -1; /* reached root */
......@@ -902,7 +880,7 @@ DWORD CDROM_Data_GetLabel(int drive, WCHAR *label)
}
else
{
MultiByteToWideChar(DOSDrives[drive].codepage, 0, (LPSTR)label_read, -1, label, 11);
MultiByteToWideChar(CP_UNIXCP, 0, (LPSTR)label_read, -1, label, 11);
label[11] = '\0';
}
return 1;
......@@ -988,7 +966,7 @@ LPCWSTR DRIVE_GetLabel( int drive )
/* FIXME: ISO9660 uses a 32 bytes long label. Should we do also? */
if (offs != -1)
MultiByteToWideChar(DOSDrives[drive].codepage, 0, buff+offs, 11,
MultiByteToWideChar(CP_UNIXCP, 0, buff+offs, 11,
DOSDrives[drive].label_read, 11);
DOSDrives[drive].label_read[11]='\0';
read = 1;
......@@ -1219,16 +1197,6 @@ UINT DRIVE_GetFlags( int drive )
}
/***********************************************************************
* DRIVE_GetCodepage
*/
UINT DRIVE_GetCodepage( int drive )
{
if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
return DOSDrives[drive].codepage;
}
/***********************************************************************
* DRIVE_Chdir
*/
int DRIVE_Chdir( int drive, LPCWSTR path )
......
......@@ -48,7 +48,6 @@ extern LPCWSTR DRIVE_GetLabel( int drive );
extern DWORD DRIVE_GetSerialNumber( int drive );
extern int DRIVE_SetSerialNumber( int drive, DWORD serial );
extern UINT DRIVE_GetFlags( int drive );
extern UINT DRIVE_GetCodepage( int drive );
extern int DRIVE_Chdir( int drive, LPCWSTR path );
extern int DRIVE_Disable( int drive );
extern int DRIVE_Enable( int drive );
......
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