ReactOS 0.4.16-dev-927-g467dec4
fopen.cpp File Reference
Include dependency graph for fopen.cpp:

Go to the source code of this file.

Functions

template<typename Character >
static FILE *__cdecl common_fsopen (Character const *const file_name, Character const *const mode, int const share_flag) throw ()
 
template<typename Character >
static errno_t __cdecl common_fopen_s (FILE **const result, Character const *const file_name, Character const *const mode) throw ()
 
FILE *__cdecl _fsopen (char const *const file, char const *const mode, int const share_flag)
 
FILE *__cdecl fopen (char const *const file, char const *const mode)
 
errno_t __cdecl fopen_s (FILE **const result, char const *const file, char const *const mode)
 
FILE *__cdecl _wfsopen (wchar_t const *const file, wchar_t const *const mode, int const share_flag)
 
FILE *__cdecl _wfopen (wchar_t const *const file, wchar_t const *const mode)
 
errno_t __cdecl _wfopen_s (FILE **const result, wchar_t const *const file, wchar_t const *const mode)
 

Function Documentation

◆ _fsopen()

FILE *__cdecl _fsopen ( char const *const  file,
char const *const  mode,
int const  share_flag 
)

Definition at line 90 of file fopen.cpp.

95{
96 return common_fsopen(file, mode, share_flag);
97}
static FILE *__cdecl common_fsopen(Character const *const file_name, Character const *const mode, int const share_flag)
Definition: fopen.cpp:22
GLenum mode
Definition: glext.h:6217
Definition: fci.c:127

◆ _wfopen()

FILE *__cdecl _wfopen ( wchar_t const *const  file,
wchar_t const *const  mode 
)

Definition at line 125 of file fopen.cpp.

129{
131}
#define _SH_DENYNO
Definition: share.h:17

◆ _wfopen_s()

errno_t __cdecl _wfopen_s ( FILE **const  result,
wchar_t const *const  file,
wchar_t const *const  mode 
)

Definition at line 133 of file fopen.cpp.

138{
139 return common_fopen_s(result, file, mode);
140}
static errno_t __cdecl common_fopen_s(FILE **const result, Character const *const file_name, Character const *const mode)
Definition: fopen.cpp:73
GLuint64EXT * result
Definition: glext.h:11304

◆ _wfsopen()

FILE *__cdecl _wfsopen ( wchar_t const *const  file,
wchar_t const *const  mode,
int const  share_flag 
)

Definition at line 116 of file fopen.cpp.

121{
122 return common_fsopen(file, mode, share_flag);
123}

◆ common_fopen_s()

template<typename Character >
static errno_t __cdecl common_fopen_s ( FILE **const  result,
Character const *const  file_name,
Character const *const  mode 
)
throw (
)
static

Definition at line 73 of file fopen.cpp.

78{
80
82 if (*result == nullptr)
83 return errno;
84
85 return 0;
86}
#define EINVAL
Definition: acclib.h:90
#define _SH_SECURE
Definition: share.h:18
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)
static LPCWSTR file_name
Definition: protocol.c:147
#define errno
Definition: errno.h:18

Referenced by _wfopen_s(), and fopen_s().

◆ common_fsopen()

template<typename Character >
static FILE *__cdecl common_fsopen ( Character const *const  file_name,
Character const *const  mode,
int const  share_flag 
)
throw (
)
static

Definition at line 22 of file fopen.cpp.

27{
28 typedef __acrt_stdio_char_traits<Character> stdio_traits;
29
30 _VALIDATE_RETURN(file_name != nullptr, EINVAL, nullptr);
31 _VALIDATE_RETURN(mode != nullptr, EINVAL, nullptr);
32 _VALIDATE_RETURN(*mode != 0, EINVAL, nullptr);
33
34 // We deliberately don't hard-validate for empty strings here. All other
35 // invalid path strings are treated as runtime errors by the inner code
36 // in _open and openfile. This is also the appropriate treatment here.
37 // Since fopen is the primary access point for file strings it might be
38 // subjected to direct user input and thus must be robust to that rather
39 // than aborting. The CRT and OS do not provide any other path validator
40 // (because Win32 doesn't allow such things to exist in full generality).
42
43 // Obtain a free stream. Note that the stream is returned locked:
45 if (!stream.valid())
46 {
47 errno = EMFILE;
48 return nullptr;
49 }
50
51 FILE* return_value = nullptr;
52 __try
53 {
54 return_value = stdio_traits::open_file(file_name, mode, share_flag, stream.public_stream());
55 }
57 {
58 if (return_value == nullptr)
60
61 stream.unlock();
62 }
64
65 return return_value;
66}
void __cdecl __acrt_stdio_free_stream(__crt_stdio_stream _Stream)
Definition: stream.cpp:97
__crt_stdio_stream __cdecl __acrt_stdio_allocate_stream()
Definition: stream.cpp:71
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
#define EMFILE
Definition: errno.h:30
#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr)
#define __try
Definition: pseh2_64.h:188
#define __endtry
Definition: pseh2_64.h:191
#define __finally
Definition: pseh2_64.h:190
Definition: parse.h:23

Referenced by _fsopen(), _wfopen(), _wfsopen(), common_fopen_s(), and fopen().

◆ fopen()

FILE *__cdecl fopen ( char const *const  file,
char const *const  mode 
)

Definition at line 99 of file fopen.cpp.

103{
105}

◆ fopen_s()

errno_t __cdecl fopen_s ( FILE **const  result,
char const *const  file,
char const *const  mode 
)

Definition at line 107 of file fopen.cpp.

112{
113 return common_fopen_s(result, file, mode);
114}