ReactOS 0.4.15-dev-7942-gd23573b
errno.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/sdk/crt/stdlib/errno.c
5 * PURPOSE: Unknown
6 * PROGRAMER: Unknown
7 *
8 */
9#include <precomp.h>
10#include "doserrmap.h"
11#include <errno.h>
13
15
16/*********************************************************************
17 * _errno (MSVCRT.@)
18 */
19int* CDECL _errno(void)
20{
21 return &(msvcrt_get_thread_data()->thread_errno);
22}
23
24/*********************************************************************
25 * __doserrno (MSVCRT.@)
26 */
27unsigned long* CDECL __doserrno(void)
28{
29 return &(msvcrt_get_thread_data()->thread_doserrno);
30}
31
32/*********************************************************************
33 * _get_errno (MSVCRT.@)
34 */
36{
37 if (!pValue)
38 return EINVAL;
39
40 *pValue = *_errno();
41 return 0;
42}
43
44/*********************************************************************
45 * _get_doserrno (MSVCRT.@)
46 */
48{
49 if (!pValue)
50 return EINVAL;
51
52 *pValue = *__doserrno();
53 return 0;
54}
55
56/*********************************************************************
57 * _set_errno (MSVCRT.@)
58 */
60{
61 *_errno() = value;
62 return 0;
63}
64
65/*********************************************************************
66 * _set_doserrno (MSVCRT.@)
67 */
69{
70 *__doserrno() = value;
71 return 0;
72}
73
74/*
75 * This function sets both doserrno to the passed in OS error code
76 * and also maps this to an appropriate errno code. The mapping
77 * has been deduced automagically by running this functions, which
78 * exists in MSVCRT but is undocumented, on all the error codes in
79 * winerror.h.
80 */
81void CDECL _dosmaperr(unsigned long oserror)
82{
83 int pos, base, lim;
84
85 _set_doserrno(oserror);
86
87 /* Use binary chop to find the corresponding errno code */
88 for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) {
89 pos = base+(lim >> 1);
90 if (doserrmap[pos].winerr == oserror) {
92 return;
93 } else if (doserrmap[pos].winerr < oserror) {
94 base = pos + 1;
95 --lim;
96 }
97 }
98 /* EINVAL appears to be the default */
100}
101
102/******************************************************************************
103* _set_error_mode (MSVCRT.@)
104*
105* Set the error mode, which describes where the C run-time writes error
106* messages.
107*
108* PARAMS
109* mode - the new error mode
110*
111* RETURNS
112* The old error mode.
113*
114*/
116
118{
119 const int old = msvcrt_error_mode;
120 if ( MSVCRT__REPORT_ERRMODE != mode ) {
122 }
123 return old;
124}
125
126/******************************************************************************
127 * _seterrormode (MSVCRT.@)
128 */
130{
132}
133
134/******************************************************************************
135 * _invalid_parameter (MSVCRT.@)
136 */
137void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func,
138 const wchar_t *file, unsigned int line, uintptr_t arg)
139{
141 else
142 {
143 ERR( "%s:%u %s: %s %lx\n", debugstr_w(file), line, debugstr_w(func), debugstr_w(expr), arg );
144#if _MSVCR_VER > 0 // FIXME: possible improvement: use a global variable in the DLL
146#endif
147 }
148}
149
150/* _get_invalid_parameter_handler - not exported in native msvcrt, added in msvcr80 */
152{
153 TRACE("\n");
155}
156
157/* _set_invalid_parameter_handler - not exproted in native msvcrt, added in msvcr80 */
160{
162
163 TRACE("(%p)\n", handler);
164
166 return old;
167}
#define EINVAL
Definition: acclib.h:90
#define __cdecl
Definition: accygwin.h:79
#define ERR(fmt,...)
Definition: debug.h:110
unsigned int uintptr_t
Definition: crtdefs.h:321
int errno_t
Definition: crtdefs.h:374
#define NULL
Definition: types.h:112
#define CDECL
Definition: compat.h:29
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:751
VOID WINAPI RaiseException(_In_ DWORD dwExceptionCode, _In_ DWORD dwExceptionFlags, _In_ DWORD nNumberOfArguments, _In_opt_ const ULONG_PTR *lpArguments)
Definition: except.c:700
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
unsigned long winerr
Definition: doserrmap.h:7
struct @4314 doserrmap[]
int en
Definition: doserrmap.h:8
PWCHAR pValue
GLenum func
Definition: glext.h:6028
GLenum mode
Definition: glext.h:6217
void(__cdecl * _invalid_parameter_handler)(const wchar_t *, const wchar_t *, const wchar_t *, unsigned int, uintptr_t)
Definition: stdlib.h:125
#define debugstr_w
Definition: kernel32.h:32
#define MSVCRT__OUT_TO_DEFAULT
Definition: msvcrt.h:669
#define MSVCRT__REPORT_ERRMODE
Definition: msvcrt.h:672
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
#define STATUS_INVALID_CRUNTIME_PARAMETER
Definition: ntstatus.h:959
void CDECL _dosmaperr(unsigned long oserror)
Definition: errno.c:81
void CDECL _seterrormode(int mode)
Definition: errno.c:129
_invalid_parameter_handler CDECL _set_invalid_parameter_handler(_invalid_parameter_handler handler)
Definition: errno.c:158
errno_t CDECL _set_doserrno(unsigned long value)
Definition: errno.c:68
int CDECL _set_error_mode(int mode)
Definition: errno.c:117
void __cdecl _invalid_parameter(const wchar_t *expr, const wchar_t *func, const wchar_t *file, unsigned int line, uintptr_t arg)
Definition: errno.c:137
static _invalid_parameter_handler invalid_parameter_handler
Definition: errno.c:14
int msvcrt_error_mode
Definition: errno.c:115
errno_t CDECL _get_doserrno(unsigned long *pValue)
Definition: errno.c:47
int *CDECL _errno(void)
Definition: errno.c:19
_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void)
Definition: errno.c:151
errno_t CDECL _set_errno(int value)
Definition: errno.c:59
errno_t CDECL _get_errno(int *pValue)
Definition: errno.c:35
unsigned long *CDECL __doserrno(void)
Definition: errno.c:27
#define TRACE(s)
Definition: solgame.cpp:4
Definition: query.h:87
Definition: fci.c:127
Definition: parser.c:49
#define EXCEPTION_NONCONTINUABLE
Definition: stubs.h:23
Definition: pdh_main.c:94