2008-06-06 17:49:24 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/crt/errno.c
|
|
|
|
* PURPOSE: Unknown
|
|
|
|
* PROGRAMER: Unknown
|
2007-03-14 20:24:57 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <precomp.h>
|
|
|
|
#include "doserrmap.h"
|
2010-06-21 19:57:36 +00:00
|
|
|
#include <errno.h>
|
2008-05-28 21:08:23 +00:00
|
|
|
#include <internal/wine/msvcrt.h>
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2010-06-21 19:57:36 +00:00
|
|
|
static _invalid_parameter_handler invalid_parameter_handler = NULL;
|
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _errno (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2014-05-12 12:52:40 +00:00
|
|
|
int CDECL *_errno(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2014-05-12 12:52:40 +00:00
|
|
|
return &(msvcrt_get_thread_data()->thread_errno);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* __doserrno (MSVCRT.@)
|
2007-03-14 20:24:57 +00:00
|
|
|
*/
|
2014-05-12 12:52:40 +00:00
|
|
|
unsigned long* CDECL __doserrno(void)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2014-05-12 12:52:40 +00:00
|
|
|
return &(msvcrt_get_thread_data()->thread_doserrno);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _get_errno (MSVCRT.@)
|
2011-12-02 21:18:42 +00:00
|
|
|
*/
|
2014-05-12 12:52:40 +00:00
|
|
|
errno_t CDECL _get_errno(int *pValue)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
if (!pValue)
|
|
|
|
return EINVAL;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
*pValue = *_errno();
|
2011-12-16 15:44:37 +00:00
|
|
|
return 0;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _get_doserrno (MSVCRT.@)
|
2011-12-02 21:18:42 +00:00
|
|
|
*/
|
2014-05-12 12:52:40 +00:00
|
|
|
errno_t CDECL _get_doserrno(unsigned long *pValue)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
if (!pValue)
|
|
|
|
return EINVAL;
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
*pValue = *__doserrno();
|
2011-12-02 21:18:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-03-14 20:24:57 +00:00
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_errno (MSVCRT.@)
|
2011-12-02 21:18:42 +00:00
|
|
|
*/
|
2014-05-12 19:44:41 +00:00
|
|
|
errno_t CDECL _set_errno(int value)
|
2011-12-02 21:18:42 +00:00
|
|
|
{
|
2014-05-12 19:44:41 +00:00
|
|
|
*_errno() = value;
|
2011-12-16 15:44:37 +00:00
|
|
|
return 0;
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 12:52:40 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* _set_doserrno (MSVCRT.@)
|
|
|
|
*/
|
2014-05-12 19:44:41 +00:00
|
|
|
errno_t CDECL _set_doserrno(unsigned long value)
|
2014-05-12 12:52:40 +00:00
|
|
|
{
|
2014-05-12 19:44:41 +00:00
|
|
|
*__doserrno() = value;
|
2014-05-12 12:52:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-14 20:24:57 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2011-12-02 21:18:42 +00:00
|
|
|
void CDECL _dosmaperr(unsigned long oserror)
|
2007-03-14 20:24:57 +00:00
|
|
|
{
|
|
|
|
int pos, base, lim;
|
|
|
|
|
2011-12-02 21:18:42 +00:00
|
|
|
_set_doserrno(oserror);
|
2007-03-14 20:24:57 +00:00
|
|
|
|
|
|
|
/* 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) {
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
_set_errno(doserrmap[pos].en);
|
2007-03-14 20:24:57 +00:00
|
|
|
return;
|
|
|
|
} else if (doserrmap[pos].winerr < oserror) {
|
|
|
|
base = pos + 1;
|
|
|
|
--lim;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* EINVAL appears to be the default */
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
_set_errno(EINVAL);
|
2007-03-14 20:24:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-28 21:08:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* _set_error_mode (MSVCRT.@)
|
|
|
|
*
|
|
|
|
* Set the error mode, which describes where the C run-time writes error
|
|
|
|
* messages.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* mode - the new error mode
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The old error mode.
|
|
|
|
*
|
|
|
|
*/
|
2011-12-02 21:18:42 +00:00
|
|
|
int msvcrt_error_mode = MSVCRT__OUT_TO_DEFAULT;
|
|
|
|
|
2008-05-28 21:08:23 +00:00
|
|
|
int CDECL _set_error_mode(int mode)
|
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
const int old = msvcrt_error_mode;
|
2008-05-28 21:08:23 +00:00
|
|
|
if ( MSVCRT__REPORT_ERRMODE != mode ) {
|
2011-12-02 21:18:42 +00:00
|
|
|
msvcrt_error_mode = mode;
|
2008-05-28 21:08:23 +00:00
|
|
|
}
|
|
|
|
return old;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2014-05-12 12:52:40 +00:00
|
|
|
* _seterrormode (MSVCRT.@)
|
|
|
|
*/
|
2008-05-28 21:08:23 +00:00
|
|
|
void CDECL _seterrormode(int mode)
|
|
|
|
{
|
|
|
|
SetErrorMode( mode );
|
|
|
|
}
|
|
|
|
|
2010-06-21 19:57:36 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* _invalid_parameter (MSVCRT.@)
|
|
|
|
*/
|
2014-05-12 12:52:40 +00:00
|
|
|
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func,
|
|
|
|
const wchar_t *file, unsigned int line, uintptr_t arg)
|
2010-06-21 19:57:36 +00:00
|
|
|
{
|
|
|
|
if (invalid_parameter_handler) invalid_parameter_handler( expr, func, file, line, arg );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR( "%s:%u %s: %s %lx\n", debugstr_w(file), line, debugstr_w(func), debugstr_w(expr), arg );
|
2014-10-23 12:17:44 +00:00
|
|
|
#if _MSVCR_VER > 0 // FIXME: possible improvement: use a global variable in the DLL
|
2010-06-21 19:57:36 +00:00
|
|
|
RaiseException( STATUS_INVALID_CRUNTIME_PARAMETER, EXCEPTION_NONCONTINUABLE, 0, NULL );
|
2014-10-23 12:17:44 +00:00
|
|
|
#endif
|
2010-06-21 19:57:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */
|
|
|
|
_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
return invalid_parameter_handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */
|
|
|
|
_invalid_parameter_handler CDECL _set_invalid_parameter_handler(
|
|
|
|
_invalid_parameter_handler handler)
|
|
|
|
{
|
|
|
|
_invalid_parameter_handler old = invalid_parameter_handler;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", handler);
|
|
|
|
|
|
|
|
invalid_parameter_handler = handler;
|
|
|
|
return old;
|
|
|
|
}
|