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
32 /*********************************************************************
33 * _initialize_onexit_table (UCRTBASE.@)
35 int __cdecl
_initialize_onexit_table(_onexit_table_t
*table
)
40 if (table
->_first
== table
->_end
)
41 table
->_last
= table
->_end
= table
->_first
= NULL
;
46 /*********************************************************************
47 * _register_onexit_function (UCRTBASE.@)
49 int __cdecl
_register_onexit_function(_onexit_table_t
*table
, _onexit_t func
)
57 table
->_first
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 32 * sizeof(void *));
60 _munlock(_EXIT_LOCK1
);
63 table
->_last
= table
->_first
;
64 table
->_end
= table
->_first
+ 32;
68 if (table
->_last
== table
->_end
)
70 int len
= table
->_end
- table
->_first
;
71 _PVFV
*tmp
= HeapReAlloc(GetProcessHeap(), 0, table
->_first
, 2 * len
* sizeof(void *));
74 _munlock(_EXIT_LOCK1
);
78 table
->_end
= table
->_first
+ 2 * len
;
79 table
->_last
= table
->_first
+ len
;
82 *table
->_last
= (_PVFV
)func
;
84 _munlock(_EXIT_LOCK1
);
89 /*********************************************************************
90 * _execute_onexit_table (UCRTBASE.@)
92 int __cdecl
_execute_onexit_table(_onexit_table_t
*table
)
101 if (!table
->_first
|| table
->_first
>= table
->_last
)
103 _munlock(_EXIT_LOCK1
);
106 copy
._first
= table
->_first
;
107 copy
._last
= table
->_last
;
108 copy
._end
= table
->_end
;
109 memset(table
, 0, sizeof(*table
));
110 _initialize_onexit_table(table
);
111 _munlock(_EXIT_LOCK1
);
113 for (func
= copy
._last
- 1; func
>= copy
._first
; func
--)
119 HeapFree(GetProcessHeap(), 0, copy
._first
);