From a27b1a9ef368342960cdbdaa0784c1c7ee60e100 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Wed, 3 Dec 2003 17:17:03 +0000 Subject: [PATCH] - Patched prsht.h bug reported by Jonathan Wilson. - Applied MSVCRT_doserrno patch by Mark Weaver . svn path=/trunk/; revision=6853 --- reactos/include/defines.h | 1 + reactos/include/msvcrt/internal/file.h | 1 + reactos/include/wine/prsht.h | 2 +- reactos/lib/msvcrt/direct/chdir.c | 10 ++++---- reactos/lib/msvcrt/direct/chdrive.c | 11 +++++++-- reactos/lib/msvcrt/direct/getcwd.c | 8 ++++++- reactos/lib/msvcrt/direct/getdcwd.c | 15 ++++++++---- reactos/lib/msvcrt/direct/mkdir.c | 5 +++- reactos/lib/msvcrt/direct/rmdir.c | 5 +++- reactos/lib/msvcrt/direct/wchdir.c | 9 ++++---- reactos/lib/msvcrt/direct/wgetcwd.c | 9 ++++++-- reactos/lib/msvcrt/direct/wgetdcwd.c | 15 ++++++++---- reactos/lib/msvcrt/direct/wmkdir.c | 5 +++- reactos/lib/msvcrt/direct/wrmdir.c | 5 +++- reactos/lib/msvcrt/io/access.c | 4 ++-- reactos/lib/msvcrt/io/chmod.c | 9 ++++++-- reactos/lib/msvcrt/io/dup.c | 15 ++++++++---- reactos/lib/msvcrt/io/filelen.c | 11 ++++++++- reactos/lib/msvcrt/io/fileleni.c | 10 +++++++- reactos/lib/msvcrt/io/find.c | 5 +++- reactos/lib/msvcrt/io/locking.c | 14 +++++++---- reactos/lib/msvcrt/io/lseek.c | 10 +++++++- reactos/lib/msvcrt/io/lseeki64.c | 2 +- reactos/lib/msvcrt/io/open.c | 18 ++++----------- reactos/lib/msvcrt/io/pipe.c | 8 ++++--- reactos/lib/msvcrt/io/read.c | 3 ++- reactos/lib/msvcrt/io/unlink.c | 10 ++++---- reactos/lib/msvcrt/io/waccess.c | 2 +- reactos/lib/msvcrt/io/wchmod.c | 8 +++++-- reactos/lib/msvcrt/io/wfind.c | 9 ++++++-- reactos/lib/msvcrt/io/wopen.c | 6 +++-- reactos/lib/msvcrt/io/write.c | 16 +++++++------ reactos/lib/msvcrt/io/wunlink.c | 6 +++-- reactos/lib/msvcrt/process/_system.c | 4 ++-- reactos/lib/msvcrt/process/threadx.c | 5 ++-- reactos/lib/msvcrt/stdlib/errno.c | 32 +++++++++++++++++++++++++- reactos/lib/user32/user32.edf | 2 +- 37 files changed, 217 insertions(+), 93 deletions(-) diff --git a/reactos/include/defines.h b/reactos/include/defines.h index c0d7b05b954..2bd011e0b1d 100644 --- a/reactos/include/defines.h +++ b/reactos/include/defines.h @@ -4920,6 +4920,7 @@ DECLARE_HANDLE(HANDLE); #ifndef __USE_W32API +#define INVALID_SET_FILE_POINTER ((DWORD)-1) typedef enum _SC_STATUS_TYPE { SC_STATUS_PROCESS_INFO = 0 diff --git a/reactos/include/msvcrt/internal/file.h b/reactos/include/msvcrt/internal/file.h index 241b18ac42f..73358805391 100644 --- a/reactos/include/msvcrt/internal/file.h +++ b/reactos/include/msvcrt/internal/file.h @@ -68,6 +68,7 @@ typedef struct __file_rec extern __file_rec* __file_rec_list; +void _dosmaperr(unsigned long oserrcode); #ifdef __cplusplus } diff --git a/reactos/include/wine/prsht.h b/reactos/include/wine/prsht.h index 6039311b754..299834b68e0 100644 --- a/reactos/include/wine/prsht.h +++ b/reactos/include/wine/prsht.h @@ -168,7 +168,7 @@ typedef struct _PROPSHEETPAGEW { LPCWSTR pszHeaderSubTitle; #endif } PROPSHEETPAGEW,*LPPROPSHEETPAGEW; -typedef const PROPSHEETPAGEA *LPCPROPSHEETPAGEW; +typedef const PROPSHEETPAGEW *LPCPROPSHEETPAGEW; typedef UINT(CALLBACK *LPFNPSPCALLBACKA)(HWND,UINT,LPPROPSHEETPAGEA); typedef UINT(CALLBACK *LPFNPSPCALLBACKW)(HWND,UINT,LPPROPSHEETPAGEW); typedef int(CALLBACK *PFNPROPSHEETCALLBACK)(HWND,UINT,LPARAM); diff --git a/reactos/lib/msvcrt/direct/chdir.c b/reactos/lib/msvcrt/direct/chdir.c index 8d2bf872774..4bc89bef8c8 100644 --- a/reactos/lib/msvcrt/direct/chdir.c +++ b/reactos/lib/msvcrt/direct/chdir.c @@ -1,16 +1,16 @@ #include #include #include - +#include /* * @implemented */ int _chdir(const char* _path) { - if (_path[1] == ':') - _chdrive(tolower(_path[0] - 'a')+1); - if (!SetCurrentDirectoryA((char*)_path)) - return -1; + if (!SetCurrentDirectoryA((char*)_path)) { + _dosmaperr(GetLastError()); + return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/direct/chdrive.c b/reactos/lib/msvcrt/direct/chdrive.c index 830b1d9c832..89cf586cbe3 100644 --- a/reactos/lib/msvcrt/direct/chdrive.c +++ b/reactos/lib/msvcrt/direct/chdrive.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include int cur_drive = 0; @@ -14,14 +16,19 @@ int _chdrive(int drive) { char d[3]; - if (!( drive >= 1 && drive <= 26)) + if (!( drive >= 1 && drive <= 26)) { + __set_errno(EINVAL); return -1; + } if (cur_drive != drive) { cur_drive = drive; d[0] = toupper(cur_drive + '@'); d[1] = ':'; d[2] = 0; - SetCurrentDirectoryA(d); + if (!SetCurrentDirectoryA(d)) { + _dosmaperr(GetLastError()); + return -1; + } } return 0; } diff --git a/reactos/lib/msvcrt/direct/getcwd.c b/reactos/lib/msvcrt/direct/getcwd.c index cd23f192db2..861a7117636 100644 --- a/reactos/lib/msvcrt/direct/getcwd.c +++ b/reactos/lib/msvcrt/direct/getcwd.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include /* @@ -12,13 +14,17 @@ char *_getcwd(char* buffer, int maxlen) int len; if (buffer == NULL) { - cwd = malloc(MAX_PATH); + if ( (cwd = malloc(MAX_PATH)) == NULL ) { + __set_errno(ENOMEM); + return NULL; + } len = MAX_PATH; } else { cwd = buffer; len = maxlen; } if (GetCurrentDirectoryA(len, cwd) == 0) { + _dosmaperr(GetLastError()); return NULL; } return cwd; diff --git a/reactos/lib/msvcrt/direct/getdcwd.c b/reactos/lib/msvcrt/direct/getdcwd.c index ab5396590dd..22e84bdcf9d 100644 --- a/reactos/lib/msvcrt/direct/getdcwd.c +++ b/reactos/lib/msvcrt/direct/getdcwd.c @@ -1,5 +1,6 @@ #include #include +#include /* * @implemented @@ -11,12 +12,16 @@ char* _getdcwd(int nDrive, char* caBuffer, int nBufLen) if (nDrive < 1 || nDrive > 26) return NULL; - if (dr != nDrive) - _chdrive(nDrive); + if (dr != nDrive) { + if ( _chdrive(nDrive) != 0 ) + return NULL; + } i = GetCurrentDirectoryA(nBufLen, caBuffer); - if (i == nBufLen) + if (i == nBufLen) return NULL; - if (dr != nDrive) - _chdrive(dr); + if (dr != nDrive) { + if ( _chdrive(dr) != 0 ) + return NULL; + } return caBuffer; } diff --git a/reactos/lib/msvcrt/direct/mkdir.c b/reactos/lib/msvcrt/direct/mkdir.c index ec950604aa2..ac5337ebb50 100644 --- a/reactos/lib/msvcrt/direct/mkdir.c +++ b/reactos/lib/msvcrt/direct/mkdir.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -7,7 +8,9 @@ */ int _mkdir(const char* _path) { - if (!CreateDirectoryA(_path, NULL)) + if (!CreateDirectoryA(_path, NULL)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/direct/rmdir.c b/reactos/lib/msvcrt/direct/rmdir.c index d178fe17c72..d469f047a66 100644 --- a/reactos/lib/msvcrt/direct/rmdir.c +++ b/reactos/lib/msvcrt/direct/rmdir.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -7,7 +8,9 @@ */ int _rmdir(const char* _path) { - if (!RemoveDirectoryA(_path)) + if (!RemoveDirectoryA(_path)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/direct/wchdir.c b/reactos/lib/msvcrt/direct/wchdir.c index 987f5e2da0c..a36451a063d 100644 --- a/reactos/lib/msvcrt/direct/wchdir.c +++ b/reactos/lib/msvcrt/direct/wchdir.c @@ -1,16 +1,17 @@ #include #include #include - +#include +#include /* * @implemented */ int _wchdir (const wchar_t *_path) { - if (_path[1] == L':') - _chdrive(towlower(_path[0] - L'a')+1); - if (!SetCurrentDirectoryW((wchar_t *)_path)) + if (!SetCurrentDirectoryW((wchar_t *)_path)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/direct/wgetcwd.c b/reactos/lib/msvcrt/direct/wgetcwd.c index c57c9f318ad..06c14516917 100644 --- a/reactos/lib/msvcrt/direct/wgetcwd.c +++ b/reactos/lib/msvcrt/direct/wgetcwd.c @@ -1,6 +1,8 @@ #include #include #include +#include +#include /* @@ -11,13 +13,16 @@ wchar_t* _wgetcwd(wchar_t* buffer, int maxlen) wchar_t *cwd; int len; if (buffer == NULL) { - cwd = malloc(MAX_PATH * sizeof(wchar_t)); + if ( (cwd = malloc(MAX_PATH * sizeof(wchar_t))) == NULL ) { + __set_errno(ENOMEM); + return NULL; + } len = MAX_PATH; } else { cwd = buffer; len = maxlen; } - if (GetCurrentDirectoryW(len, cwd) == 0 ) + if (GetCurrentDirectoryW(len, cwd) == 0) return NULL; return cwd; } diff --git a/reactos/lib/msvcrt/direct/wgetdcwd.c b/reactos/lib/msvcrt/direct/wgetdcwd.c index e13e28ac5c9..56e56eab9f5 100644 --- a/reactos/lib/msvcrt/direct/wgetdcwd.c +++ b/reactos/lib/msvcrt/direct/wgetdcwd.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -13,15 +14,19 @@ wchar_t* _wgetdcwd(int nDrive, wchar_t* caBuffer, int nBufLen) if (nDrive < 1 || nDrive > 26) return NULL; - if (dr != nDrive) - _chdrive(nDrive); + if (dr != nDrive) { + if ( _chdrive(nDrive) != 0 ) + return NULL; + } i = GetCurrentDirectoryW(nBufLen, caBuffer); - if (i == nBufLen) + if (i == nBufLen) return NULL; - if (dr != nDrive) - _chdrive(dr); + if (dr != nDrive) { + if ( _chdrive(dr) != 0 ) + return NULL; + } return caBuffer; } diff --git a/reactos/lib/msvcrt/direct/wmkdir.c b/reactos/lib/msvcrt/direct/wmkdir.c index 653d0f11bb4..148a9e07191 100644 --- a/reactos/lib/msvcrt/direct/wmkdir.c +++ b/reactos/lib/msvcrt/direct/wmkdir.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -7,7 +8,9 @@ */ int _wmkdir(const wchar_t* _path) { - if (!CreateDirectoryW(_path, NULL)) + if (!CreateDirectoryW(_path, NULL)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/direct/wrmdir.c b/reactos/lib/msvcrt/direct/wrmdir.c index e96c343512a..c0c569170d3 100644 --- a/reactos/lib/msvcrt/direct/wrmdir.c +++ b/reactos/lib/msvcrt/direct/wrmdir.c @@ -1,12 +1,15 @@ #include #include +#include /* * @implemented */ int _wrmdir(const wchar_t* _path) { - if (!RemoveDirectoryW(_path)) + if (!RemoveDirectoryW(_path)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/io/access.c b/reactos/lib/msvcrt/io/access.c index 9472e6ca757..e54f92cedc0 100644 --- a/reactos/lib/msvcrt/io/access.c +++ b/reactos/lib/msvcrt/io/access.c @@ -13,8 +13,8 @@ int _access( const char *_path, int _amode ) DWORD Attributes = GetFileAttributesA(_path); DPRINT("_access('%s', %x)\n", _path, _amode); - if (Attributes == -1) { - __set_errno(ENOENT); + if (Attributes == -1) { + _dosmaperr(GetLastError()); return -1; } if ((_amode & W_OK) == W_OK) { diff --git a/reactos/lib/msvcrt/io/chmod.c b/reactos/lib/msvcrt/io/chmod.c index df2bc6206ec..08614ece0a1 100644 --- a/reactos/lib/msvcrt/io/chmod.c +++ b/reactos/lib/msvcrt/io/chmod.c @@ -1,5 +1,6 @@ #include #include +#include #define NDEBUG #include @@ -16,8 +17,10 @@ int _chmod(const char* filename, mode_t mode) DPRINT("_chmod('%s', %x)\n", filename, mode); FileAttributes = GetFileAttributesA(filename); - if ( FileAttributes == -1 ) + if ( FileAttributes == -1 ) { + _dosmaperr(GetLastError()); return -1; + } if ( mode == 0 ) return -1; @@ -29,8 +32,10 @@ int _chmod(const char* filename, mode_t mode) else FileAttributes &= FILE_ATTRIBUTE_NORMAL; - if (SetFileAttributesA(filename, FileAttributes) == FALSE) + if (SetFileAttributesA(filename, FileAttributes) == FALSE) { + _dosmaperr(GetLastError()); return -1; + } return 1; } diff --git a/reactos/lib/msvcrt/io/dup.c b/reactos/lib/msvcrt/io/dup.c index 5e8b8b06fc5..94bf6bcaf2e 100644 --- a/reactos/lib/msvcrt/io/dup.c +++ b/reactos/lib/msvcrt/io/dup.c @@ -1,6 +1,7 @@ -/* $Id: dup.c,v 1.5 2003/07/11 21:57:54 royce Exp $ */ +/* $Id: dup.c,v 1.6 2003/12/03 17:17:03 navaraf Exp $ */ #include #include +#include #include @@ -15,8 +16,10 @@ int _dup(int handle) int fd; hFile = _get_osfhandle(handle); - if (hFile == INVALID_HANDLE_VALUE) - return -1; + if (hFile == INVALID_HANDLE_VALUE) { + __set_errno(EBADF); + return -1; + } result = DuplicateHandle(hProcess, hFile, hProcess, @@ -24,8 +27,10 @@ int _dup(int handle) 0, TRUE, DUPLICATE_SAME_ACCESS); - if (result == FALSE) - return -1; + if (result == FALSE) { + _dosmaperr(GetLastError()); + return -1; + } fd = __fileno_alloc(hFile, __fileno_getmode(handle)); if (fd < 0) diff --git a/reactos/lib/msvcrt/io/filelen.c b/reactos/lib/msvcrt/io/filelen.c index 086c4dc6417..ce047623077 100644 --- a/reactos/lib/msvcrt/io/filelen.c +++ b/reactos/lib/msvcrt/io/filelen.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -7,5 +8,13 @@ */ long _filelength(int _fd) { - return GetFileSize(_get_osfhandle(_fd), NULL); + DWORD len = GetFileSize(_get_osfhandle(_fd), NULL); + if (len == INVALID_FILE_SIZE) { + DWORD oserror = GetLastError(); + if (oserror != 0) { + _dosmaperr(oserror); + return -1L; + } + } + return (long)len; } diff --git a/reactos/lib/msvcrt/io/fileleni.c b/reactos/lib/msvcrt/io/fileleni.c index 5b809cbf048..f7d91a3a754 100644 --- a/reactos/lib/msvcrt/io/fileleni.c +++ b/reactos/lib/msvcrt/io/fileleni.c @@ -1,5 +1,6 @@ #include #include +#include /* @@ -7,8 +8,15 @@ */ __int64 _filelengthi64(int _fd) { - long lo_length, hi_length; + DWORD lo_length, hi_length; lo_length = GetFileSize(_get_osfhandle(_fd), &hi_length); + if (lo_length == INVALID_FILE_SIZE) { + DWORD oserror = GetLastError(); + if (oserror != 0) { + _dosmaperr(oserror); + return (__int64)-1; + } + } return((((__int64)hi_length) << 32) + lo_length); } diff --git a/reactos/lib/msvcrt/io/find.c b/reactos/lib/msvcrt/io/find.c index a67b983eb74..1f1013092dd 100644 --- a/reactos/lib/msvcrt/io/find.c +++ b/reactos/lib/msvcrt/io/find.c @@ -39,6 +39,7 @@ int _findfirst(const char* _name, struct _finddata_t* result) hFindFile = (long)FindFirstFileA(dir, &FindFileData); if (hFindFile == -1) { memset(result,0,sizeof(struct _finddata_t)); + _dosmaperr(GetLastError()); return -1; } @@ -71,8 +72,10 @@ int _findnext(int handle, struct _finddata_t* result) if (handle == 0 || handle == -1) return 0; - if (!FindNextFileA((void*)handle, &FindFileData)) + if (!FindNextFileA((void*)handle, &FindFileData)) { + _dosmaperr(GetLastError()); return -1; + } result->attrib = FindFileData.dwFileAttributes; result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL); diff --git a/reactos/lib/msvcrt/io/locking.c b/reactos/lib/msvcrt/io/locking.c index 860c7828480..80a0d748aa5 100644 --- a/reactos/lib/msvcrt/io/locking.c +++ b/reactos/lib/msvcrt/io/locking.c @@ -1,15 +1,19 @@ #include #include - +#include /* * @implemented */ int _locking(int _fd, int mode, long nbytes) { - long offset = _lseek(_fd, 0L, 1); - if (!LockFile(_get_osfhandle(_fd),offset,0,nbytes,0)) - return -1; + long offset = _lseek(_fd, 0L, 1); + if (offset == -1L) + return -1; + if (!LockFile(_get_osfhandle(_fd),offset,0,nbytes,0)) { + _dosmaperr(GetLastError()); + return -1; + } - return 0; + return 0; } diff --git a/reactos/lib/msvcrt/io/lseek.c b/reactos/lib/msvcrt/io/lseek.c index 9ecc5e6ac66..89fe8a72342 100644 --- a/reactos/lib/msvcrt/io/lseek.c +++ b/reactos/lib/msvcrt/io/lseek.c @@ -8,5 +8,13 @@ */ long _lseek(int _fildes, long _offset, int _whence) { - return (SetFilePointer((HANDLE)filehnd(_fildes), _offset, NULL, _whence)); + DWORD newpos = SetFilePointer((HANDLE)filehnd(_fildes), _offset, NULL, _whence); + if (newpos == INVALID_SET_FILE_POINTER) { + DWORD oserror = GetLastError(); + if (oserror != 0) { + _dosmaperr(oserror); + return -1L; + } + } + return newpos; } diff --git a/reactos/lib/msvcrt/io/lseeki64.c b/reactos/lib/msvcrt/io/lseeki64.c index 83c45e72029..83fda098015 100644 --- a/reactos/lib/msvcrt/io/lseeki64.c +++ b/reactos/lib/msvcrt/io/lseeki64.c @@ -21,7 +21,7 @@ __int64 _lseeki64(int _fildes, __int64 _offset, int _whence) // } if (SetFilePointerEx((HANDLE)filehnd(_fildes), offset, &new_pos, _whence)) { } else { - //__set_errno ( EINVAL ); + _dosmaperr(error); return -1L; } return new_pos.QuadPart; diff --git a/reactos/lib/msvcrt/io/open.c b/reactos/lib/msvcrt/io/open.c index cf17a9ad054..87fc6a6a308 100644 --- a/reactos/lib/msvcrt/io/open.c +++ b/reactos/lib/msvcrt/io/open.c @@ -1,4 +1,4 @@ -/* $Id: open.c,v 1.16 2003/08/05 15:41:03 weiden Exp $ +/* $Id: open.c,v 1.17 2003/12/03 17:17:03 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -105,7 +105,6 @@ int _open(const char* _path, int _oflag,...) DWORD dwShareMode = 0; DWORD dwCreationDistribution = 0; DWORD dwFlagsAndAttributes = 0; - DWORD dwLastError; SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; #if !defined(NDEBUG) && defined(DBG) @@ -185,17 +184,10 @@ int _open(const char* _path, int _oflag,...) dwCreationDistribution, dwFlagsAndAttributes, NULL); - if (hFile == (HANDLE)-1) { - dwLastError = GetLastError(); - if (dwLastError == ERROR_ALREADY_EXISTS) { - DPRINT("ERROR_ALREADY_EXISTS\n"); - __set_errno(EEXIST); - } else { - DPRINT("%x\n", dwLastError); - __set_errno(ENOFILE); - } - return -1; - } + if (hFile == (HANDLE)-1) { + _dosmaperr(GetLastError()); + return -1; + } DPRINT("OK\n"); if (!(_oflag & (_O_TEXT|_O_BINARY))) { _oflag |= _fmode; diff --git a/reactos/lib/msvcrt/io/pipe.c b/reactos/lib/msvcrt/io/pipe.c index 8792abb453a..7a2665a91a8 100644 --- a/reactos/lib/msvcrt/io/pipe.c +++ b/reactos/lib/msvcrt/io/pipe.c @@ -1,4 +1,4 @@ -/* $Id: pipe.c,v 1.6 2003/07/11 21:57:54 royce Exp $ +/* $Id: pipe.c,v 1.7 2003/12/03 17:17:03 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -25,8 +25,10 @@ int _pipe(int _fildes[2], unsigned int size, int mode ) if (mode & O_NOINHERIT) sa.bInheritHandle = FALSE; - if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) - return -1; + if (!CreatePipe(&hReadPipe,&hWritePipe,&sa,size)) { + _dosmaperr(GetLastError()); + return -1; + } if ((_fildes[0] = __fileno_alloc(hReadPipe, mode)) < 0) { diff --git a/reactos/lib/msvcrt/io/read.c b/reactos/lib/msvcrt/io/read.c index 8ddc9ffbfd5..ffd4ffc51ff 100644 --- a/reactos/lib/msvcrt/io/read.c +++ b/reactos/lib/msvcrt/io/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.11 2003/07/11 21:57:54 royce Exp $ +/* $Id: read.c,v 1.12 2003/12/03 17:17:03 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -46,6 +46,7 @@ size_t _read(int _fd, void *_buf, size_t _nbyte) { return 0; } + _dosmaperr(error); return -1; } diff --git a/reactos/lib/msvcrt/io/unlink.c b/reactos/lib/msvcrt/io/unlink.c index 8efa997b754..27843651a5d 100644 --- a/reactos/lib/msvcrt/io/unlink.c +++ b/reactos/lib/msvcrt/io/unlink.c @@ -19,10 +19,10 @@ */ int _unlink(const char* filename) { - int result = 0; DPRINT("_unlink('%s')\n", filename); - if (!DeleteFileA(filename)) - result = -1; - DPRINT("%d\n", result); - return result; + if (!DeleteFileA(filename)) { + _dosmaperr(GetLastError()); + return -1; + } + return 0; } diff --git a/reactos/lib/msvcrt/io/waccess.c b/reactos/lib/msvcrt/io/waccess.c index 85a894e22ce..0e93fbd2d5a 100644 --- a/reactos/lib/msvcrt/io/waccess.c +++ b/reactos/lib/msvcrt/io/waccess.c @@ -13,7 +13,7 @@ int _waccess(const wchar_t *_path, int _amode) DWORD Attributes = GetFileAttributesW(_path); if (Attributes == -1) { - __set_errno(ENOENT); + _dosmaperr(GetLastError()); return -1; } if ((_amode & W_OK) == W_OK) { diff --git a/reactos/lib/msvcrt/io/wchmod.c b/reactos/lib/msvcrt/io/wchmod.c index 9762acdd519..60f04ebdb40 100644 --- a/reactos/lib/msvcrt/io/wchmod.c +++ b/reactos/lib/msvcrt/io/wchmod.c @@ -16,8 +16,10 @@ int _wchmod(const wchar_t* filename, mode_t mode) DPRINT("_wchmod('%S', %x)\n", filename, mode); FileAttributes = GetFileAttributesW(filename); - if ( FileAttributes == -1 ) + if ( FileAttributes == -1 ) { + _dosmaperr(GetLastError()); return -1; + } if ( mode == 0 ) return -1; @@ -29,8 +31,10 @@ int _wchmod(const wchar_t* filename, mode_t mode) else FileAttributes &= FILE_ATTRIBUTE_NORMAL; - if (SetFileAttributesW(filename, FileAttributes) == FALSE) + if (SetFileAttributesW(filename, FileAttributes) == FALSE) { + _dosmaperr(GetLastError()); return -1; + } return 1; } diff --git a/reactos/lib/msvcrt/io/wfind.c b/reactos/lib/msvcrt/io/wfind.c index 5e2eacd99d6..50c59a4ae25 100644 --- a/reactos/lib/msvcrt/io/wfind.c +++ b/reactos/lib/msvcrt/io/wfind.c @@ -28,6 +28,7 @@ int _wfindfirst(const wchar_t* _name, struct _wfinddata_t* result) hFindFile = (long)FindFirstFileW(dir, &FindFileData); if (hFindFile == -1) { memset(result,0,sizeof(struct _wfinddata_t)); + _dosmaperr(GetLastError()); return -1; } @@ -75,6 +76,7 @@ int _findfirsti64(const char *_name, struct _finddatai64_t *result) if (hFindFile == -1) { memset(result,0,sizeof(struct _finddatai64_t)); + _dosmaperr(GetLastError()); return -1; } @@ -107,8 +109,10 @@ int _findnexti64(int handle, struct _finddatai64_t *result) if (handle == 0 || handle == -1) return 0; - if (!FindNextFileA((void *)handle, &FindFileData)) - return -1; + if (!FindNextFileA((void *)handle, &FindFileData)) { + _dosmaperr(GetLastError()); + return -1; + } result->attrib = FindFileData.dwFileAttributes; result->time_create = FileTimeToUnixTime(&FindFileData.ftCreationTime,NULL); @@ -148,6 +152,7 @@ int _wfindfirsti64(const wchar_t *_name, struct _wfinddatai64_t *result) if (hFindFile == -1) { memset(result,0,sizeof(struct _wfinddatai64_t)); + _dosmaperr(GetLastError()); return -1; } diff --git a/reactos/lib/msvcrt/io/wopen.c b/reactos/lib/msvcrt/io/wopen.c index 012e80cf9ed..ae4bbf3d346 100644 --- a/reactos/lib/msvcrt/io/wopen.c +++ b/reactos/lib/msvcrt/io/wopen.c @@ -1,4 +1,4 @@ -/* $Id: wopen.c,v 1.3 2003/07/11 21:57:54 royce Exp $ +/* $Id: wopen.c,v 1.4 2003/12/03 17:17:03 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -132,8 +132,10 @@ int _wopen(const wchar_t* _path, int _oflag, ...) dwCreationDistribution, dwFlagsAndAttributes, NULL); - if (hFile == (HANDLE)-1) + if (hFile == (HANDLE)-1) { + _dosmaperr(GetLastError()); return -1; + } return __fileno_alloc(hFile,_oflag); } diff --git a/reactos/lib/msvcrt/io/write.c b/reactos/lib/msvcrt/io/write.c index 01d2d091027..f4ca807ba4c 100644 --- a/reactos/lib/msvcrt/io/write.c +++ b/reactos/lib/msvcrt/io/write.c @@ -12,6 +12,7 @@ #include #include #include +#include #define NDEBUG #include @@ -48,7 +49,8 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte) result = _nbyte; tmp = (char*) malloc(BUFSIZE); if (tmp == NULL) { - return -1; + __set_errno(ENOMEM); + return -1; } count = BUFSIZE; out = tmp; @@ -76,10 +78,10 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte) if (count == 0 || _nbyte == 0) { int tmp_len_debug = strlen(tmp); if (!WriteFile(_get_osfhandle(_fd), tmp, BUFSIZE - count, &wbyte, NULL)) { - //ReportLastError(); - result = -1; - tmp_len_debug = 0; - break; + _dosmaperr(GetLastError()); + result = -1; + tmp_len_debug = 0; + break; } if (wbyte < (BUFSIZE - count)) { result = in - (char*)_buf; @@ -93,8 +95,8 @@ size_t _write(int _fd, const void* _buf, size_t _nbyte) return result; } else { if(!WriteFile(_get_osfhandle(_fd), _buf, _nbyte, &wbyte, NULL)) { - //ReportLastError(); - return -1; + _dosmaperr(GetLastError()); + return -1; } return wbyte; } diff --git a/reactos/lib/msvcrt/io/wunlink.c b/reactos/lib/msvcrt/io/wunlink.c index 51ce61f6ace..a573af38162 100644 --- a/reactos/lib/msvcrt/io/wunlink.c +++ b/reactos/lib/msvcrt/io/wunlink.c @@ -12,7 +12,7 @@ #define NDEBUG #include - +#include /* * @implemented @@ -20,7 +20,9 @@ int _wunlink(const wchar_t* filename) { DPRINT("_wunlink('%S')\n", filename); - if (!DeleteFileW(filename)) + if (!DeleteFileW(filename)) { + _dosmaperr(GetLastError()); return -1; + } return 0; } diff --git a/reactos/lib/msvcrt/process/_system.c b/reactos/lib/msvcrt/process/_system.c index 5d71e0a085c..3548fb64d92 100644 --- a/reactos/lib/msvcrt/process/_system.c +++ b/reactos/lib/msvcrt/process/_system.c @@ -1,4 +1,4 @@ -/* $Id: _system.c,v 1.8 2003/08/05 15:41:03 weiden Exp $ +/* $Id: _system.c,v 1.9 2003/12/03 17:17:03 navaraf Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -110,7 +110,7 @@ int system(const char *command) if (result == FALSE) { - __set_errno(ENOEXEC); + _dosmaperr(GetLastError()); return -1; } diff --git a/reactos/lib/msvcrt/process/threadx.c b/reactos/lib/msvcrt/process/threadx.c index 35671e6459f..465ccf2b7e2 100644 --- a/reactos/lib/msvcrt/process/threadx.c +++ b/reactos/lib/msvcrt/process/threadx.c @@ -1,4 +1,4 @@ -/* $Id: threadx.c,v 1.5 2003/11/14 17:13:31 weiden Exp $ +/* $Id: threadx.c,v 1.6 2003/12/03 17:17:03 navaraf Exp $ * */ #include @@ -29,8 +29,7 @@ unsigned long _beginthreadex( arglist, initflag, (PULONG)thrdaddr ); if (NULL == NewThread) { - /* FIXME map GetLastError() to errno */ - __set_errno ( ENOSYS ); + _dosmaperr( GetLastError() ); } return (unsigned long) NewThread; diff --git a/reactos/lib/msvcrt/stdlib/errno.c b/reactos/lib/msvcrt/stdlib/errno.c index 5016f7e1fb3..c912ba5bb8a 100644 --- a/reactos/lib/msvcrt/stdlib/errno.c +++ b/reactos/lib/msvcrt/stdlib/errno.c @@ -1,4 +1,4 @@ -/* $Id: errno.c,v 1.10 2003/07/16 17:53:34 royce Exp $ +/* $Id: errno.c,v 1.11 2003/12/03 17:17:03 navaraf Exp $ * */ @@ -6,6 +6,8 @@ #include #include +#include "doserrmap.h" + /* * @implemented */ @@ -45,4 +47,32 @@ int __set_errno(int error) return(error); } +/* + * This function sets both doserrno to the passed in OS error code + * and also maps this to an appropriate errno code. The mapping + * has been deduced automagically by running this functions, which + * exists in MSVCRT but is undocumented, on all the error codes in + * winerror.h. + */ +void _dosmaperr(unsigned long oserror) +{ + int pos, base, lim; + + __set_doserrno(oserror); + + /* Use binary chop to find the corresponding errno code */ + for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) { + pos = base+(lim >> 1); + if (doserrmap[pos].winerr == oserror) { + __set_errno(doserrmap[pos].en); + return; + } else if (doserrmap[pos].winerr > oserror) { + base = pos + 1; + --lim; + } + } + /* EINVAL appears to be the default */ + __set_errno(EINVAL); +} + /* EOF */ diff --git a/reactos/lib/user32/user32.edf b/reactos/lib/user32/user32.edf index 846f58d8979..aea59a08f95 100644 --- a/reactos/lib/user32/user32.edf +++ b/reactos/lib/user32/user32.edf @@ -212,7 +212,7 @@ EnumDesktopsA=EnumDesktopsA@12 EnumDesktopsW=EnumDesktopsW@12 EnumDisplayDevicesA=EnumDisplayDevicesA@16 EnumDisplayDevicesW=EnumDisplayDevicesW@16 -EnumDisplayMonitors=EnumDisplayMonitors@16 +;EnumDisplayMonitors=EnumDisplayMonitors@16 EnumDisplaySettingsA=EnumDisplaySettingsA@12 EnumDisplaySettingsExA=EnumDisplaySettingsExA@16 EnumDisplaySettingsExW=EnumDisplaySettingsExW@16