ReactOS
0.4.16-dev-1946-g52006dd
setmaxf.cpp
Go to the documentation of this file.
1
//
2
// setmaxf.cpp
3
//
4
// Copyright (c) Microsoft Corporation. All rights reserved.
5
//
6
// Defines _setmaxstdio() and _getmaxstdio(), which control the maximum number
7
// of stdio streams that may be open simultaneously.
8
//
9
#include <
corecrt_internal_stdio.h
>
10
11
12
13
// Sets the maximum number of stdio streams that may be simultaneously open.
14
// Note that the maximum must be at least _IOB_ENTRIES, and must be no larger
15
// than _N_HANDLE_. However, it may be either larger or smaller than the current
16
// maximum.
17
//
18
// Returns the new maximum value on success; returns -1 on failure.
19
extern
"C"
int
__cdecl
_setmaxstdio
(
int
const
new_maximum)
20
{
21
// Make sure the request is reasonable:
22
_VALIDATE_RETURN
(new_maximum >=
_IOB_ENTRIES
&& new_maximum <=
_NHANDLE_
,
EINVAL
, -1);
23
24
return
__acrt_lock_and_call(
__acrt_stdio_index_lock
, [&]
25
{
26
// If the new maximum is the same as our current maximum, no work to do:
27
if
(new_maximum ==
_nstream
)
28
return
new_maximum;
29
30
// If the new maximum is smaller than the current maximum, attempt to
31
// free up any entries that are beyond the new maximum:
32
if
(new_maximum <
_nstream
)
33
{
34
__crt_stdio_stream_data
**
const
first_to_remove =
__piob
+ new_maximum;
35
__crt_stdio_stream_data
**
const
last_to_remove =
__piob
+
_nstream
;
36
for
(
__crt_stdio_stream_data
** rit = last_to_remove; rit != first_to_remove; --rit)
37
{
38
__crt_stdio_stream_data
*
const
entry
= *(rit - 1);
39
if
(
entry
==
nullptr
)
40
continue
;
41
42
// If the entry is still in use, stop freeing entries and return
43
// failure to the caller:
44
if
(
__crt_stdio_stream
(
entry
).is_in_use())
45
return
-1;
46
47
_free_crt
(
entry
);
48
}
49
}
50
51
// Enlarge or shrink the array, as required:
52
__crt_stdio_stream_data
**
const
new_piob = _recalloc_crt_t(
__crt_stdio_stream_data
*,
__piob
, new_maximum).detach();
53
if
(new_piob ==
nullptr
)
54
return
-1;
55
56
_nstream
= new_maximum;
57
__piob
= new_piob;
58
return
new_maximum;
59
});
60
}
61
62
63
64
// Gets the maximum number of stdio streams that may be open at any one time.
65
extern
"C"
int
__cdecl
_getmaxstdio
()
66
{
67
return
__acrt_lock_and_call(
__acrt_stdio_index_lock
, []
68
{
69
return
_nstream
;
70
});
71
}
EINVAL
#define EINVAL
Definition:
acclib.h:90
__cdecl
#define __cdecl
Definition:
accygwin.h:79
__crt_stdio_stream
Definition:
corecrt_internal_stdio.h:197
__acrt_stdio_index_lock
@ __acrt_stdio_index_lock
Definition:
corecrt_internal.h:946
_NHANDLE_
#define _NHANDLE_
Definition:
corecrt_internal_lowio.h:120
corecrt_internal_stdio.h
_nstream
int _nstream
Definition:
corecrt_internal_stdio.h:310
__piob
__crt_stdio_stream_data ** __piob
Definition:
corecrt_internal_stdio.h:316
_VALIDATE_RETURN
#define _VALIDATE_RETURN(expr, errorcode, retexpr)
Definition:
corecrt_internal_strtox.h:38
_IOB_ENTRIES
#define _IOB_ENTRIES
Definition:
stdio.h:23
_free_crt
#define _free_crt
Definition:
internal_shared.h:175
entry
uint32_t entry
Definition:
isohybrid.c:63
_setmaxstdio
int __cdecl _setmaxstdio(int const new_maximum)
Definition:
setmaxf.cpp:19
_getmaxstdio
int __cdecl _getmaxstdio()
Definition:
setmaxf.cpp:65
__crt_stdio_stream_data
Definition:
corecrt_internal_stdio.h:167
sdk
lib
ucrt
stdio
setmaxf.cpp
Generated on Thu Dec 4 2025 06:16:22 for ReactOS by
1.9.6