2 * msvcrt onexit functions
4 * Copyright 2016 Nikolay Sivov
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* these functions are part of the import lib for compatibility with the Mingw runtime */
23 #pragma makedep implib
31 /*********************************************************************
32 * _initialize_onexit_table (UCRTBASE.@)
34 int __cdecl
_initialize_onexit_table(_onexit_table_t
*table
)
39 if (table
->_first
== table
->_end
)
40 table
->_last
= table
->_end
= table
->_first
= NULL
;
45 /*********************************************************************
46 * _register_onexit_function (UCRTBASE.@)
48 int __cdecl
_register_onexit_function(_onexit_table_t
*table
, _onexit_t func
)
56 table
->_first
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 32 * sizeof(void *));
62 table
->_last
= table
->_first
;
63 table
->_end
= table
->_first
+ 32;
67 if (table
->_last
== table
->_end
)
69 int len
= table
->_end
- table
->_first
;
70 _PVFV
*tmp
= HeapReAlloc(GetProcessHeap(), 0, table
->_first
, 2 * len
* sizeof(void *));
77 table
->_end
= table
->_first
+ 2 * len
;
78 table
->_last
= table
->_first
+ len
;
81 *table
->_last
= (_PVFV
)func
;
88 /*********************************************************************
89 * _execute_onexit_table (UCRTBASE.@)
91 int __cdecl
_execute_onexit_table(_onexit_table_t
*table
)
100 if (!table
->_first
|| table
->_first
>= table
->_last
)
102 _unlock(_EXIT_LOCK1
);
105 copy
._first
= table
->_first
;
106 copy
._last
= table
->_last
;
107 copy
._end
= table
->_end
;
108 memset(table
, 0, sizeof(*table
));
109 _initialize_onexit_table(table
);
110 _unlock(_EXIT_LOCK1
);
112 for (func
= copy
._last
- 1; func
>= copy
._first
; func
--)
118 HeapFree(GetProcessHeap(), 0, copy
._first
);