ReactOS 0.4.15-dev-8119-g4fb2fdb
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
14/*********************************************************************
15 * _errno (MSVCRT.@)
16 */
17int* CDECL _errno(void)
18{
19 return &(msvcrt_get_thread_data()->thread_errno);
20}
21
22/*********************************************************************
23 * __doserrno (MSVCRT.@)
24 */
25unsigned long* CDECL __doserrno(void)
26{
27 return &(msvcrt_get_thread_data()->thread_doserrno);
28}
29
30/*********************************************************************
31 * _get_errno (MSVCRT.@)
32 */
34{
35 if (!pValue)
36 return EINVAL;
37
38 *pValue = *_errno();
39 return 0;
40}
41
42/*********************************************************************
43 * _get_doserrno (MSVCRT.@)
44 */
46{
47 if (!pValue)
48 return EINVAL;
49
50 *pValue = *__doserrno();
51 return 0;
52}
53
54/*********************************************************************
55 * _set_errno (MSVCRT.@)
56 */
58{
59 *_errno() = value;
60 return 0;
61}
62
63/*********************************************************************
64 * _set_doserrno (MSVCRT.@)
65 */
67{
68 *__doserrno() = value;
69 return 0;
70}
71
72/*
73 * This function sets both doserrno to the passed in OS error code
74 * and also maps this to an appropriate errno code. The mapping
75 * has been deduced automagically by running this functions, which
76 * exists in MSVCRT but is undocumented, on all the error codes in
77 * winerror.h.
78 */
79void CDECL _dosmaperr(unsigned long oserror)
80{
81 int pos, base, lim;
82
83 _set_doserrno(oserror);
84
85 /* Use binary chop to find the corresponding errno code */
86 for (base=0, lim=sizeof(doserrmap)/sizeof(doserrmap[0]); lim; lim >>= 1) {
87 pos = base+(lim >> 1);
88 if (doserrmap[pos].winerr == oserror) {
90 return;
91 } else if (doserrmap[pos].winerr < oserror) {
92 base = pos + 1;
93 --lim;
94 }
95 }
96 /* EINVAL appears to be the default */
98}
99
100/******************************************************************************
101* _set_error_mode (MSVCRT.@)
102*
103* Set the error mode, which describes where the C run-time writes error
104* messages.
105*
106* PARAMS
107* mode - the new error mode
108*
109* RETURNS
110* The old error mode.
111*
112*/
114
116{
117 const int old = msvcrt_error_mode;
118 if ( MSVCRT__REPORT_ERRMODE != mode ) {
120 }
121 return old;
122}
123
124/******************************************************************************
125 * _seterrormode (MSVCRT.@)
126 */
128{
130}
#define EINVAL
Definition: acclib.h:90
int errno_t
Definition: crtdefs.h:374
#define CDECL
Definition: compat.h:29
UINT WINAPI SetErrorMode(IN UINT uMode)
Definition: except.c:751
unsigned long winerr
Definition: doserrmap.h:7
struct @4319 doserrmap[]
int en
Definition: doserrmap.h:8
PWCHAR pValue
GLenum mode
Definition: glext.h:6217
#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
void CDECL _dosmaperr(unsigned long oserror)
Definition: errno.c:79
void CDECL _seterrormode(int mode)
Definition: errno.c:127
errno_t CDECL _set_doserrno(unsigned long value)
Definition: errno.c:66
int CDECL _set_error_mode(int mode)
Definition: errno.c:115
int msvcrt_error_mode
Definition: errno.c:113
errno_t CDECL _get_doserrno(unsigned long *pValue)
Definition: errno.c:45
int *CDECL _errno(void)
Definition: errno.c:17
errno_t CDECL _set_errno(int value)
Definition: errno.c:57
errno_t CDECL _get_errno(int *pValue)
Definition: errno.c:33
unsigned long *CDECL __doserrno(void)
Definition: errno.c:25
Definition: pdh_main.c:94