Commit 4ff2a27c authored by Alexandre Julliard's avatar Alexandre Julliard

Changed DOS extended error handling to be based on SetLastError;

should be more thread-safe this way.
parent a27b48b1
...@@ -294,7 +294,7 @@ BOOL32 WINAPI CreateDirectory32A( LPCSTR path, ...@@ -294,7 +294,7 @@ BOOL32 WINAPI CreateDirectory32A( LPCSTR path,
if (DOSFS_GetDevice( path )) if (DOSFS_GetDevice( path ))
{ {
TRACE(file, "cannot use device '%s'!\n",path); TRACE(file, "cannot use device '%s'!\n",path);
DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk ); SetLastError( ERROR_ACCESS_DENIED );
return FALSE; return FALSE;
} }
if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0; if (!DOSFS_GetFullName( path, FALSE, &full_name )) return 0;
...@@ -362,7 +362,7 @@ BOOL32 WINAPI RemoveDirectory32A( LPCSTR path ) ...@@ -362,7 +362,7 @@ BOOL32 WINAPI RemoveDirectory32A( LPCSTR path )
if (DOSFS_GetDevice( path )) if (DOSFS_GetDevice( path ))
{ {
TRACE(file, "cannot remove device '%s'!\n", path); TRACE(file, "cannot remove device '%s'!\n", path);
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_FILE_NOT_FOUND );
return FALSE; return FALSE;
} }
if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE; if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
...@@ -401,7 +401,7 @@ static BOOL32 DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name, ...@@ -401,7 +401,7 @@ static BOOL32 DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name,
if ((p_s >= full_name->short_name + sizeof(full_name->short_name) - 14) || if ((p_s >= full_name->short_name + sizeof(full_name->short_name) - 14) ||
(p_l >= full_name->long_name + sizeof(full_name->long_name) - 1)) (p_l >= full_name->long_name + sizeof(full_name->long_name) - 1))
{ {
DOS_ERROR( ER_PathNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_PATH_NOT_FOUND );
return FALSE; return FALSE;
} }
if (!DOSFS_FindUnixName( dir->long_name, name, p_l, if (!DOSFS_FindUnixName( dir->long_name, name, p_l,
......
...@@ -72,12 +72,6 @@ static const DOS_DEVICE DOSFS_Devices[] = ...@@ -72,12 +72,6 @@ static const DOS_DEVICE DOSFS_Devices[] =
#define GET_DRIVE(path) \ #define GET_DRIVE(path) \
(((path)[1] == ':') ? toupper((path)[0]) - 'A' : DOSFS_CurDrive) (((path)[1] == ':') ? toupper((path)[0]) - 'A' : DOSFS_CurDrive)
/* DOS extended error status */
WORD DOS_ExtendedError;
BYTE DOS_ErrorClass;
BYTE DOS_ErrorAction;
BYTE DOS_ErrorLocus;
/* Directory info for DOSFS_ReadDir */ /* Directory info for DOSFS_ReadDir */
typedef struct typedef struct
{ {
...@@ -319,7 +313,7 @@ static DOS_DIR *DOSFS_OpenDir( LPCSTR path ) ...@@ -319,7 +313,7 @@ static DOS_DIR *DOSFS_OpenDir( LPCSTR path )
DOS_DIR *dir = HeapAlloc( SystemHeap, 0, sizeof(*dir) ); DOS_DIR *dir = HeapAlloc( SystemHeap, 0, sizeof(*dir) );
if (!dir) if (!dir)
{ {
DOS_ERROR( ER_OutOfMemory, EC_OutOfResource, SA_Abort, EL_Memory ); SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return NULL; return NULL;
} }
...@@ -716,7 +710,7 @@ static int DOSFS_GetPathDrive( const char **name ) ...@@ -716,7 +710,7 @@ static int DOSFS_GetPathDrive( const char **name )
if (!DRIVE_IsValid(drive)) if (!DRIVE_IsValid(drive))
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return -1; return -1;
} }
return drive; return drive;
...@@ -800,7 +794,7 @@ BOOL32 DOSFS_GetFullName( LPCSTR name, BOOL32 check_last, DOS_FULL_NAME *full ) ...@@ -800,7 +794,7 @@ BOOL32 DOSFS_GetFullName( LPCSTR name, BOOL32 check_last, DOS_FULL_NAME *full )
if ((p_s >= full->short_name + sizeof(full->short_name) - 14) || if ((p_s >= full->short_name + sizeof(full->short_name) - 14) ||
(p_l >= full->long_name + sizeof(full->long_name) - 1)) (p_l >= full->long_name + sizeof(full->long_name) - 1))
{ {
DOS_ERROR( ER_PathNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_PATH_NOT_FOUND );
return FALSE; return FALSE;
} }
...@@ -841,12 +835,12 @@ BOOL32 DOSFS_GetFullName( LPCSTR name, BOOL32 check_last, DOS_FULL_NAME *full ) ...@@ -841,12 +835,12 @@ BOOL32 DOSFS_GetFullName( LPCSTR name, BOOL32 check_last, DOS_FULL_NAME *full )
{ {
if (check_last) if (check_last)
{ {
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_FILE_NOT_FOUND );
return FALSE; return FALSE;
} }
if (*name) /* Not last */ if (*name) /* Not last */
{ {
DOS_ERROR( ER_PathNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_PATH_NOT_FOUND );
return FALSE; return FALSE;
} }
} }
...@@ -1052,7 +1046,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCSTR name, DWORD len, LPSTR result, ...@@ -1052,7 +1046,7 @@ static DWORD DOSFS_DoGetFullPathName( LPCSTR name, DWORD len, LPSTR result,
} }
} }
if ( *endchar ) if ( *endchar )
{ DOS_ERROR( ER_PathNotFound, EC_NotFound, SA_Abort, EL_Disk ); { SetLastError( ERROR_PATH_NOT_FOUND );
return 0; return 0;
} }
while (!IS_END_OF_NAME(*name) && (!*endchar) ) while (!IS_END_OF_NAME(*name) && (!*endchar) )
...@@ -1330,7 +1324,7 @@ HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATA32A *data ) ...@@ -1330,7 +1324,7 @@ HANDLE16 WINAPI FindFirstFile16( LPCSTR path, WIN32_FIND_DATA32A *data )
if (!FindNextFile16( handle, data )) if (!FindNextFile16( handle, data ))
{ {
FindClose16( handle ); FindClose16( handle );
DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_NO_MORE_FILES );
return INVALID_HANDLE_VALUE16; return INVALID_HANDLE_VALUE16;
} }
return handle; return handle;
...@@ -1381,13 +1375,13 @@ BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data ) ...@@ -1381,13 +1375,13 @@ BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data )
if (!(info = (FIND_FIRST_INFO *)GlobalLock16( handle ))) if (!(info = (FIND_FIRST_INFO *)GlobalLock16( handle )))
{ {
DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_HANDLE );
return FALSE; return FALSE;
} }
GlobalUnlock16( handle ); GlobalUnlock16( handle );
if (!info->path || !info->dir) if (!info->path || !info->dir)
{ {
DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_NO_MORE_FILES );
return FALSE; return FALSE;
} }
if (!DOSFS_FindNextEx( info, data )) if (!DOSFS_FindNextEx( info, data ))
...@@ -1395,7 +1389,7 @@ BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data ) ...@@ -1395,7 +1389,7 @@ BOOL16 WINAPI FindNextFile16( HANDLE16 handle, WIN32_FIND_DATA32A *data )
DOSFS_CloseDir( info->dir ); info->dir = NULL; DOSFS_CloseDir( info->dir ); info->dir = NULL;
HeapFree( SystemHeap, 0, info->path ); HeapFree( SystemHeap, 0, info->path );
info->path = info->long_mask = NULL; info->path = info->long_mask = NULL;
DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_NO_MORE_FILES );
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
...@@ -1440,7 +1434,7 @@ BOOL16 WINAPI FindClose16( HANDLE16 handle ) ...@@ -1440,7 +1434,7 @@ BOOL16 WINAPI FindClose16( HANDLE16 handle )
if ((handle == INVALID_HANDLE_VALUE16) || if ((handle == INVALID_HANDLE_VALUE16) ||
!(info = (FIND_FIRST_INFO *)GlobalLock16( handle ))) !(info = (FIND_FIRST_INFO *)GlobalLock16( handle )))
{ {
DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_HANDLE );
return FALSE; return FALSE;
} }
if (info->dir) DOSFS_CloseDir( info->dir ); if (info->dir) DOSFS_CloseDir( info->dir );
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "windows.h" #include "windows.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h"
#include "drive.h" #include "drive.h"
#include "file.h" #include "file.h"
#include "heap.h" #include "heap.h"
...@@ -267,7 +268,7 @@ int DRIVE_SetCurrentDrive( int drive ) ...@@ -267,7 +268,7 @@ int DRIVE_SetCurrentDrive( int drive )
TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() ); TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
if (!DRIVE_IsValid( drive )) if (!DRIVE_IsValid( drive ))
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return 0; return 0;
} }
TRACE(dosfs, "%c:\n", 'A' + drive ); TRACE(dosfs, "%c:\n", 'A' + drive );
...@@ -460,7 +461,7 @@ int DRIVE_Chdir( int drive, const char *path ) ...@@ -460,7 +461,7 @@ int DRIVE_Chdir( int drive, const char *path )
if (!FILE_Stat( full_name.long_name, &info )) return 0; if (!FILE_Stat( full_name.long_name, &info )) return 0;
if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{ {
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk ); SetLastError( ERROR_FILE_NOT_FOUND );
return 0; return 0;
} }
unix_cwd = full_name.long_name + strlen( DOSDrives[drive].root ); unix_cwd = full_name.long_name + strlen( DOSDrives[drive].root );
...@@ -493,7 +494,7 @@ int DRIVE_Disable( int drive ) ...@@ -493,7 +494,7 @@ int DRIVE_Disable( int drive )
{ {
if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root) if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return 0; return 0;
} }
DOSDrives[drive].flags |= DRIVE_DISABLED; DOSDrives[drive].flags |= DRIVE_DISABLED;
...@@ -508,7 +509,7 @@ int DRIVE_Enable( int drive ) ...@@ -508,7 +509,7 @@ int DRIVE_Enable( int drive )
{ {
if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root) if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return 0; return 0;
} }
DOSDrives[drive].flags &= ~DRIVE_DISABLED; DOSDrives[drive].flags &= ~DRIVE_DISABLED;
...@@ -533,7 +534,7 @@ int DRIVE_SetLogicalMapping ( int existing_drive, int new_drive ) ...@@ -533,7 +534,7 @@ int DRIVE_SetLogicalMapping ( int existing_drive, int new_drive )
!old->root || !old->root ||
(new_drive < 0) || (new_drive >= MAX_DOS_DRIVES)) (new_drive < 0) || (new_drive >= MAX_DOS_DRIVES))
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return 0; return 0;
} }
...@@ -644,7 +645,7 @@ static int DRIVE_GetFreeSpace( int drive, LPULARGE_INTEGER size, ...@@ -644,7 +645,7 @@ static int DRIVE_GetFreeSpace( int drive, LPULARGE_INTEGER size,
if (!DRIVE_IsValid(drive)) if (!DRIVE_IsValid(drive))
{ {
DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk ); SetLastError( ERROR_INVALID_DRIVE );
return 0; return 0;
} }
......
...@@ -113,15 +113,6 @@ extern struct DosDeviceStruct LPT[MAX_PORTS]; ...@@ -113,15 +113,6 @@ extern struct DosDeviceStruct LPT[MAX_PORTS];
#define FA_ARCHIVE 0x20 /* Archive */ #define FA_ARCHIVE 0x20 /* Archive */
#define FA_UNUSED 0x40 /* Unused */ #define FA_UNUSED 0x40 /* Unused */
extern WORD DOS_ExtendedError;
extern BYTE DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus;
#define DOS_ERROR(err,class,action,locus) \
( SetLastError(err), \
DOS_ErrorClass = (class), DOS_ErrorAction = (action), \
DOS_ErrorLocus = (locus), DOS_ExtendedError = (err) )
/* Error codes */ /* Error codes */
#define ER_NoError 0x00 #define ER_NoError 0x00
......
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