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

Go to the source code of this file.

Functions

static __crt_stdio_stream __cdecl find_or_allocate_unused_stream_nolock () throw ()
 
__crt_stdio_stream __cdecl __acrt_stdio_allocate_stream () throw ()
 
void __cdecl __acrt_stdio_free_stream (__crt_stdio_stream stream) throw ()
 

Function Documentation

◆ __acrt_stdio_allocate_stream()

__crt_stdio_stream __cdecl __acrt_stdio_allocate_stream ( )
throw (
)

Definition at line 71 of file stream.cpp.

72{
74
76 __try
77 {
79 if (!stream.valid())
80 __leave;
81
82 stream->_cnt = 0;
83 stream->_tmpfname = nullptr;
84 stream->_ptr = nullptr;
85 stream->_base = nullptr;
86 stream->_file = -1;
87 }
89 {
91 }
93
94 return stream;
95}
void __cdecl __acrt_unlock(_In_ __acrt_lock_id lock)
Definition: locks.cpp:57
@ __acrt_stdio_index_lock
__acrt_lock(__acrt_heap_lock)
#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
static __crt_stdio_stream __cdecl find_or_allocate_unused_stream_nolock()
Definition: stream.cpp:12
Definition: parse.h:23

Referenced by _Success_(), common_fdopen(), and common_fsopen().

◆ __acrt_stdio_free_stream()

void __cdecl __acrt_stdio_free_stream ( __crt_stdio_stream  stream)
throw (
)

Definition at line 97 of file stream.cpp.

98{
99 stream->_ptr = nullptr;
100 stream->_base = nullptr;
101 stream->_cnt = 0;
102 stream->_file = -1;
103 stream->_charbuf = 0;
104 stream->_bufsiz = 0;
105 stream->_tmpfname = nullptr;
106 stream.deallocate();
107}

Referenced by _fclose_internal(), _fclose_nolock_internal(), _Success_(), and common_fsopen().

◆ find_or_allocate_unused_stream_nolock()

static __crt_stdio_stream __cdecl find_or_allocate_unused_stream_nolock ( )
throw (
)
static

Definition at line 12 of file stream.cpp.

13{
14 __crt_stdio_stream_data** const first_stream = __piob + _IOB_ENTRIES;
15 __crt_stdio_stream_data** const last_stream = first_stream + _nstream - _IOB_ENTRIES;
16
17 for (__crt_stdio_stream_data** it = first_stream; it != last_stream; ++it)
18 {
19 // First, check to see whether the stream is valid and free for use:
20 {
22 if (stream.valid())
23 {
24 if (stream.is_in_use())
25 continue;
26
27 stream.lock();
28 if (!stream.try_allocate())
29 {
30 stream.unlock();
31 continue;
32 }
33
34 return stream;
35 }
36 }
37
38 // Otherwise, there is no stream at this index yet, so we allocate one
39 // and return it:
40 {
41 *it = _calloc_crt_t(__crt_stdio_stream_data, 1).detach();
42 if (*it == nullptr)
43 break;
44
45 // Initialize the stream. Everything requires zero-initialization
46 // (which we get from calloc), except the file handle and the lock:
47 (*it)->_file = -1;
49
51
52 // Note: This attempt will always succeed, because we hold the only
53 // pointer to the stream object (since we just allocated it):
54 stream.try_allocate();
55 stream.lock();
56
57 return stream;
58 }
59 }
60
61 return __crt_stdio_stream();
62}
#define _CORECRT_SPINCOUNT
BOOL WINAPI __acrt_InitializeCriticalSectionEx(_Out_ LPCRITICAL_SECTION critical_section, _In_ DWORD spin_count, _In_ DWORD flags)
int _nstream
__crt_stdio_stream_data ** __piob
#define _IOB_ENTRIES
Definition: stdio.h:23

Referenced by __acrt_stdio_allocate_stream().