xref: /reactos/sdk/lib/ucrt/startup/initterm.cpp (revision 04e0dc4a)
1 //
2 // initterm.cpp
3 //
4 //      Copyright (c) Microsoft Corporation. All rights reserved.
5 //
6 // _initterm and _initterm_e functions used during dynamic initialization.
7 //
8 #include <corecrt_internal.h>
9 
10 
11 
12 // Calls each function in [first, last).  [first, last) must be a valid range of
13 // function pointers.  Each function is called, in order.
_initterm(_PVFV * const first,_PVFV * const last)14 extern "C" void __cdecl _initterm(_PVFV* const first, _PVFV* const last)
15 {
16     for (_PVFV* it = first; it != last; ++it)
17     {
18         if (*it == nullptr)
19             continue;
20 
21         (**it)();
22     }
23 }
24 
25 // Calls each function in [first, last).  [first, last) must be a valid range of
26 // function pointers.  Each function must return zero on success, nonzero on
27 // failure.  If any function returns nonzero, iteration stops immediately and
28 // the nonzero value is returned.  Otherwise all functions are called and zero
29 // is returned.
30 //
31 // If a nonzero value is returned, it is expected to be one of the runtime error
32 // values (_RT_{NAME}, defined in the internal header files).
_initterm_e(_PIFV * const first,_PIFV * const last)33 extern "C" int __cdecl _initterm_e(_PIFV* const first, _PIFV* const last)
34 {
35     for (_PIFV* it = first; it != last; ++it)
36     {
37         if (*it == nullptr)
38             continue;
39 
40         int const result = (**it)();
41         if (result != 0)
42             return result;
43     }
44 
45     return 0;
46 }
47