ReactOS  0.4.14-dev-358-gbef841c
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>
12 #include <internal/wine/msvcrt.h>
13 
15 
16 /*********************************************************************
17  * _errno (MSVCRT.@)
18  */
19 int* CDECL _errno(void)
20 {
21  return &(msvcrt_get_thread_data()->thread_errno);
22 }
23 
24 /*********************************************************************
25  * __doserrno (MSVCRT.@)
26  */
27 unsigned long* CDECL __doserrno(void)
28 {
29  return &(msvcrt_get_thread_data()->thread_doserrno);
30 }
31 
32 /*********************************************************************
33  * _get_errno (MSVCRT.@)
34  */
35 errno_t CDECL _get_errno(int *pValue)
36 {
37  if (!pValue)
38  return EINVAL;
39 
40  *pValue = *_errno();
41  return 0;
42 }
43 
44 /*********************************************************************
45  * _get_doserrno (MSVCRT.@)
46  */
47 errno_t CDECL _get_doserrno(unsigned long *pValue)
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  */
81 void 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 {
131  SetErrorMode( mode );
132 }
133 
134 /******************************************************************************
135  * _invalid_parameter (MSVCRT.@)
136  */
137 void __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 }
GLenum func
Definition: glext.h:6028
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:753
#define __cdecl
Definition: accygwin.h:79
Definition: arc.h:39
int en
Definition: doserrmap.h:8
int *CDECL _errno(void)
Definition: errno.c:19
#define MSVCRT__REPORT_ERRMODE
Definition: msvcrt.h:672
#define EXCEPTION_NONCONTINUABLE
Definition: rtltypes.h:150
int CDECL _set_error_mode(int mode)
Definition: errno.c:117
errno_t CDECL _get_doserrno(unsigned long *pValue)
Definition: errno.c:47
Definition: query.h:86
static _invalid_parameter_handler invalid_parameter_handler
Definition: errno.c:14
_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
GLuint base
Definition: 3dtext.c:35
#define debugstr_w
Definition: kernel32.h:32
unsigned int uintptr_t
Definition: crtdefs.h:300
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
void CDECL _seterrormode(int mode)
Definition: errno.c:129
int errno_t
Definition: crtdefs.h:353
void CDECL _dosmaperr(unsigned long oserror)
Definition: errno.c:81
errno_t CDECL _set_errno(int value)
Definition: errno.c:59
#define TRACE(s)
Definition: solgame.cpp:4
#define MSVCRT__OUT_TO_DEFAULT
Definition: msvcrt.h:669
struct @3933 doserrmap[]
GLenum mode
Definition: glext.h:6217
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
GLsizei const GLfloat * value
Definition: glext.h:6069
#define ERR(fmt,...)
Definition: debug.h:109
unsigned long winerr
Definition: doserrmap.h:7
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
VOID WINAPI RaiseException(IN DWORD dwExceptionCode, IN DWORD dwExceptionFlags, IN DWORD nNumberOfArguments, IN CONST ULONG_PTR *lpArguments OPTIONAL)
Definition: except.c:693
#define CDECL
Definition: compat.h:21
errno_t CDECL _get_errno(int *pValue)
Definition: errno.c:35
int msvcrt_error_mode
Definition: errno.c:115
void(__cdecl * _invalid_parameter_handler)(const wchar_t *, const wchar_t *, const wchar_t *, unsigned int, uintptr_t)
Definition: stdlib.h:137
unsigned long *CDECL __doserrno(void)
Definition: errno.c:27
#define STATUS_INVALID_CRUNTIME_PARAMETER
Definition: ntstatus.h:945
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7786
_invalid_parameter_handler CDECL _get_invalid_parameter_handler(void)
Definition: errno.c:151
Definition: fci.c:126