ReactOS 0.4.16-dev-814-g656a5dc
freopen.cpp File Reference
Include dependency graph for freopen.cpp:

Go to the source code of this file.

Functions

template<typename Character >
static errno_t __cdecl common_freopen (FILE **const result, Character const *const file_name, Character const *const mode, __crt_stdio_stream const stream, int const share_flag) throw ()
 
FILE *__cdecl freopen (char const *const file_name, char const *const mode, FILE *const public_stream)
 
errno_t __cdecl freopen_s (FILE **const result, char const *const file_name, char const *const mode, FILE *const public_stream)
 
FILE *__cdecl _wfreopen (wchar_t const *const file_name, wchar_t const *const mode, FILE *const public_stream)
 
errno_t __cdecl _wfreopen_s (FILE **const result, wchar_t const *const file_name, wchar_t const *const mode, FILE *const public_stream)
 

Function Documentation

◆ _wfreopen()

FILE *__cdecl _wfreopen ( wchar_t const *const  file_name,
wchar_t const *const  mode,
FILE *const  public_stream 
)

Definition at line 110 of file freopen.cpp.

115{
116 FILE* result_stream = nullptr;
117 common_freopen(&result_stream, file_name, mode, __crt_stdio_stream(public_stream), _SH_DENYNO);
118 return result_stream;
119}
#define _SH_DENYNO
Definition: share.h:17
static errno_t __cdecl common_freopen(FILE **const result, Character const *const file_name, Character const *const mode, __crt_stdio_stream const stream, int const share_flag)
Definition: freopen.cpp:21
GLenum mode
Definition: glext.h:6217
static LPCWSTR file_name
Definition: protocol.c:147

◆ _wfreopen_s()

errno_t __cdecl _wfreopen_s ( FILE **const  result,
wchar_t const *const  file_name,
wchar_t const *const  mode,
FILE *const  public_stream 
)

Definition at line 121 of file freopen.cpp.

127{
129}
#define _SH_SECURE
Definition: share.h:18
GLuint64EXT * result
Definition: glext.h:11304

◆ common_freopen()

template<typename Character >
static errno_t __cdecl common_freopen ( FILE **const  result,
Character const *const  file_name,
Character const *const  mode,
__crt_stdio_stream const  stream,
int const  share_flag 
)
throw (
)
static

Definition at line 21 of file freopen.cpp.

28{
29 typedef __acrt_stdio_char_traits<Character> stdio_traits;
30
32 *result = nullptr;
33
34 // C11 7.21.5.4/3: "If filename is a null pointer, the freopen function
35 // attempts to change the mode of the stream to that specified by mode, as
36 // if the name of the file currently associated with the stream had been
37 // used. It is implementation-defined which changes of mode are permitted
38 // (if any), and under what circumstances."
39 //
40 // In our implementation, we do not currently support changing the mode
41 // in this way. In the future, we might consider use of ReOpenFile to
42 // implement support for changing the mode.
44
47
48 // Just as in the common_fsopen function, we do not hard-validate empty
49 // 'file_name' strings in this function:
51
52 errno_t return_value = 0;
53
54 _lock_file(stream.public_stream());
55 __try
56 {
57 // If the stream is in use, try to close it, ignoring possible errors:
58 if (stream.is_in_use())
59 _fclose_nolock(stream.public_stream());
60
61 stream->_ptr = nullptr;
62 stream->_base = nullptr;
63 stream->_cnt = 0;
64 stream.unset_flags(-1);
65
66 // We may have called fclose above, which will deallocate the stream.
67 // We still hold the lock on the stream, though, so we can just reset
68 // the allocated flag to retain ownership.
69 stream.set_flags(_IOALLOCATED);
70
71 *result = stdio_traits::open_file(file_name, mode, share_flag, stream.public_stream());
72 if (*result == nullptr)
73 {
74 stream.unset_flags(_IOALLOCATED);
75 return_value = errno;
76 }
77 }
79 {
80 _unlock_file(stream.public_stream());
81 }
83
84 return return_value;
85}
#define EINVAL
Definition: acclib.h:90
#define EBADF
Definition: acclib.h:82
_CRTIMP void __cdecl _unlock_file(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl _fclose_nolock(_Inout_ FILE *_File)
_CRTIMP void __cdecl _lock_file(_Inout_ FILE *_File)
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
#define _VALIDATE_RETURN_ERRCODE_NOEXC(expr, errorcode)
#define __try
Definition: pseh2_64.h:172
#define __endtry
Definition: pseh2_64.h:175
#define __finally
Definition: pseh2_64.h:174
#define errno
Definition: errno.h:18
Definition: parse.h:23
int errno_t
Definition: corecrt.h:615

Referenced by _wfreopen(), _wfreopen_s(), freopen(), and freopen_s().

◆ freopen()

FILE *__cdecl freopen ( char const *const  file_name,
char const *const  mode,
FILE *const  public_stream 
)

Definition at line 89 of file freopen.cpp.

94{
95 FILE* result_stream = nullptr;
96 common_freopen(&result_stream, file_name, mode, __crt_stdio_stream(public_stream), _SH_DENYNO);
97 return result_stream;
98}

◆ freopen_s()

errno_t __cdecl freopen_s ( FILE **const  result,
char const *const  file_name,
char const *const  mode,
FILE *const  public_stream 
)

Definition at line 100 of file freopen.cpp.

106{
108}