ReactOS 0.4.16-dev-937-g7afcd2a
setmode.cpp File Reference
#include <corecrt_internal_lowio.h>
#include <stdlib.h>
Include dependency graph for setmode.cpp:

Go to the source code of this file.

Functions

int __cdecl _setmode (int const fh, int const mode)
 
int __cdecl _setmode_nolock (int const fh, int const mode)
 
errno_t __cdecl _set_fmode (int const mode)
 
errno_t __cdecl _get_fmode (int *const pMode)
 

Function Documentation

◆ _get_fmode()

errno_t __cdecl _get_fmode ( int *const  pMode)

Definition at line 113 of file setmode.cpp.

114{
115 _VALIDATE_RETURN_ERRCODE(pMode != nullptr, EINVAL);
116
118 *pMode = __crt_interlocked_read(&_fmode.value());
120
121 return 0;
122}
#define EINVAL
Definition: acclib.h:90
#define _fmode
Definition: stdlib.h:255
#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
#define _END_SECURE_CRT_DEPRECATION_DISABLE
char * value
Definition: compiler.c:67

◆ _set_fmode()

errno_t __cdecl _set_fmode ( int const  mode)

Definition at line 100 of file setmode.cpp.

101{
103
105 _InterlockedExchange(reinterpret_cast<long*>(&_fmode.value()), mode);
107
108 return 0;
109}
#define _O_BINARY
Definition: cabinet.h:51
#define _O_TEXT
Definition: cabinet.h:50
GLenum mode
Definition: glext.h:6217
#define _O_WTEXT
Definition: fcntl.h:20
long __cdecl _InterlockedExchange(_Interlocked_operand_ long volatile *_Target, long _Value)

◆ _setmode()

int __cdecl _setmode ( int const  fh,
int const  mode 
)

Definition at line 19 of file setmode.cpp.

20{
22 mode == _O_BINARY ||
23 mode == _O_WTEXT ||
24 mode == _O_U8TEXT ||
26 EINVAL, -1);
27
28 _CHECK_FH_RETURN(fh, EBADF, -1);
29 _VALIDATE_RETURN((fh >= 0 && (unsigned)fh < (unsigned)_nhandle), EBADF, -1);
30 _VALIDATE_RETURN((_osfile(fh) & FOPEN), EBADF, -1);
31
33 int result = -1;
34 __try
35 {
36 if ((_osfile(fh) & FOPEN) == 0)
37 {
38 errno = EBADF;
39 _ASSERTE(("Invalid file descriptor. File possibly closed by a different thread",0));
40 __leave;
41 }
42
44 }
46 {
48 }
50 return result;
51}
#define EBADF
Definition: acclib.h:82
#define _CHECK_FH_RETURN(handle, errorcode, retexpr)
int _nhandle
Definition: ioinit.cpp:34
void __cdecl __acrt_lowio_lock_fh(_In_ int _FileHandle)
void __cdecl __acrt_lowio_unlock_fh(_In_ int _FileHandle)
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define _ASSERTE(expr)
Definition: crtdbg.h:114
#define FOPEN
GLuint64EXT * result
Definition: glext.h:11304
#define _O_U8TEXT
Definition: fcntl.h:22
#define _O_U16TEXT
Definition: fcntl.h:21
#define __try
Definition: pseh2_64.h:188
#define __leave
Definition: pseh2_64.h:192
#define __endtry
Definition: pseh2_64.h:191
#define __finally
Definition: pseh2_64.h:190
#define errno
Definition: errno.h:18
#define _osfile(i)
Definition: internal.h:72
int __cdecl _setmode_nolock(int const fh, int const mode)
Definition: setmode.cpp:55

◆ _setmode_nolock()

int __cdecl _setmode_nolock ( int const  fh,
int const  mode 
)

Definition at line 55 of file setmode.cpp.

56{
57 int const old_mode = _osfile(fh) & FTEXT;
58 __crt_lowio_text_mode const old_textmode = _textmode(fh);
59
60 switch (mode)
61 {
62 case _O_BINARY:
63 _osfile(fh) &= ~FTEXT;
64 break;
65
66 case _O_TEXT:
67 _osfile(fh) |= FTEXT;
69 break;
70
71 case _O_U8TEXT:
72 _osfile(fh) |= FTEXT;
74 break;
75
76 case _O_U16TEXT:
77 case _O_WTEXT:
78 _osfile(fh) |= FTEXT;
80 break;
81 }
82
83 if (old_mode == 0)
84 return _O_BINARY;
85
86 if (old_textmode == __crt_lowio_text_mode::ansi)
87 {
88 return _O_TEXT;
89 }
90 else if (old_textmode == __crt_lowio_text_mode::utf8)
91 {
92 return _O_U8TEXT;
93 }
94
95 return _O_WTEXT;
96}
__crt_lowio_text_mode
#define _textmode(i)
Definition: internal.h:74

Referenced by _setmode().