From f0d7ce034e5ce2be397a49a8e37d4f9a51759a54 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Thu, 4 Dec 2003 13:23:26 +0000 Subject: [PATCH] - Fixed MSVCRTand CRTDLL building. svn path=/trunk/; revision=6859 --- reactos/lib/crtdll/stdlib/errno.c | 32 ++++++++++- reactos/lib/msvcrt/stdlib/doserrmap.h | 82 +++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 reactos/lib/msvcrt/stdlib/doserrmap.h diff --git a/reactos/lib/crtdll/stdlib/errno.c b/reactos/lib/crtdll/stdlib/errno.c index a44eda924f6..cf721e5ff41 100644 --- a/reactos/lib/crtdll/stdlib/errno.c +++ b/reactos/lib/crtdll/stdlib/errno.c @@ -1,5 +1,6 @@ #include #include +#include "../../msvcrt/stdlib/doserrmap.h" #undef errno int errno; @@ -18,15 +19,12 @@ int *_errno(void) return &errno; } - int __set_errno (int error) { errno = error; return error; } - - /* * @implemented */ @@ -43,3 +41,31 @@ int* __doserrno(void) _doserrno = GetLastError(); return &_doserrno; } + +/* + * 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; + + SetLastError(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); +} diff --git a/reactos/lib/msvcrt/stdlib/doserrmap.h b/reactos/lib/msvcrt/stdlib/doserrmap.h new file mode 100644 index 00000000000..3b1307146f4 --- /dev/null +++ b/reactos/lib/msvcrt/stdlib/doserrmap.h @@ -0,0 +1,82 @@ +/* doserrmap.h: auto-generated from winerror.h and errno.h using undoc'd _dosmaperr. */ + +#ifndef doserrmap_h +#define doserrmap_h + +struct { + unsigned long winerr; + int en; +} doserrmap[] = { + { ERROR_FILE_NOT_FOUND, ENOENT }, + { ERROR_PATH_NOT_FOUND, ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, + { ERROR_ACCESS_DENIED, EACCES }, + { ERROR_INVALID_HANDLE, EBADF }, + { ERROR_ARENA_TRASHED, ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, + { ERROR_INVALID_BLOCK, ENOMEM }, + { ERROR_BAD_ENVIRONMENT, E2BIG }, + { ERROR_BAD_FORMAT, ENOEXEC }, + { ERROR_INVALID_DRIVE, ENOENT }, + { ERROR_CURRENT_DIRECTORY, EACCES }, + { ERROR_NOT_SAME_DEVICE, EXDEV }, + { ERROR_NO_MORE_FILES, ENOENT }, + { ERROR_WRITE_PROTECT, EACCES }, + { ERROR_BAD_UNIT, EACCES }, + { ERROR_NOT_READY, EACCES }, + { ERROR_BAD_COMMAND, EACCES }, + { ERROR_CRC, EACCES }, + { ERROR_BAD_LENGTH, EACCES }, + { ERROR_SEEK, EACCES }, + { ERROR_NOT_DOS_DISK, EACCES }, + { ERROR_SECTOR_NOT_FOUND, EACCES }, + { ERROR_OUT_OF_PAPER, EACCES }, + { ERROR_WRITE_FAULT, EACCES }, + { ERROR_READ_FAULT, EACCES }, + { ERROR_GEN_FAILURE, EACCES }, + { ERROR_SHARING_VIOLATION, EACCES }, + { ERROR_LOCK_VIOLATION, EACCES }, + { ERROR_WRONG_DISK, EACCES }, + { ERROR_SHARING_BUFFER_EXCEEDED, EACCES }, + { ERROR_BAD_NETPATH, ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, EACCES }, + { ERROR_BAD_NET_NAME, ENOENT }, + { ERROR_FILE_EXISTS, EEXIST }, + { ERROR_CANNOT_MAKE, EACCES }, + { ERROR_FAIL_I24, EACCES }, + { ERROR_NO_PROC_SLOTS, EAGAIN }, + { ERROR_DRIVE_LOCKED, EACCES }, + { ERROR_BROKEN_PIPE, EPIPE }, + { ERROR_DISK_FULL, ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, EBADF }, + { ERROR_WAIT_NO_CHILDREN, ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, + { ERROR_SEEK_ON_DEVICE, EACCES }, + { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, + { ERROR_NOT_LOCKED, EACCES }, + { ERROR_BAD_PATHNAME, ENOENT }, + { ERROR_MAX_THRDS_REACHED, EAGAIN }, + { ERROR_LOCK_FAILED, EACCES }, + { ERROR_ALREADY_EXISTS, EEXIST }, + { ERROR_INVALID_STARTING_CODESEG, ENOEXEC }, + { ERROR_INVALID_STACKSEG, ENOEXEC }, + { ERROR_INVALID_MODULETYPE, ENOEXEC }, + { ERROR_INVALID_EXE_SIGNATURE, ENOEXEC }, + { ERROR_EXE_MARKED_INVALID, ENOEXEC }, + { ERROR_BAD_EXE_FORMAT, ENOEXEC }, + { ERROR_ITERATED_DATA_EXCEEDS_64k, ENOEXEC }, + { ERROR_INVALID_MINALLOCSIZE, ENOEXEC }, + { ERROR_DYNLINK_FROM_INVALID_RING, ENOEXEC }, + { ERROR_IOPL_NOT_ENABLED, ENOEXEC }, + { ERROR_INVALID_SEGDPL, ENOEXEC }, + { ERROR_AUTODATASEG_EXCEEDS_64k, ENOEXEC }, + { ERROR_RING2SEG_MUST_BE_MOVABLE, ENOEXEC }, + { ERROR_RELOC_CHAIN_XEEDS_SEGLIM, ENOEXEC }, + { ERROR_INFLOOP_IN_RELOC_CHAIN, ENOEXEC }, + { ERROR_FILENAME_EXCED_RANGE, ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } +}; + +#endif /* doserrmap_h */