directmanipulation: Return S_OK form viewport_SetViewportOptions stub.
[wine/zf.git] / dlls / msvcrt / onexit.c
blob18b935b88d98b735bdd0a57a43acf2432030c947
1 /*
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 */
22 #if 0
23 #pragma makedep implib
24 #endif
26 #define _CRTIMP
27 #include <process.h>
28 #include "msvcrt.h"
29 #include "mtdll.h"
32 /*********************************************************************
33 * _initialize_onexit_table (UCRTBASE.@)
35 int __cdecl _initialize_onexit_table(_onexit_table_t *table)
37 if (!table)
38 return -1;
40 if (table->_first == table->_end)
41 table->_last = table->_end = table->_first = NULL;
42 return 0;
46 /*********************************************************************
47 * _register_onexit_function (UCRTBASE.@)
49 int __cdecl _register_onexit_function(_onexit_table_t *table, _onexit_t func)
51 if (!table)
52 return -1;
54 _mlock(_EXIT_LOCK1);
55 if (!table->_first)
57 table->_first = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 32 * sizeof(void *));
58 if (!table->_first)
60 _munlock(_EXIT_LOCK1);
61 return -1;
63 table->_last = table->_first;
64 table->_end = table->_first + 32;
67 /* grow if full */
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 *));
72 if (!tmp)
74 _munlock(_EXIT_LOCK1);
75 return -1;
77 table->_first = tmp;
78 table->_end = table->_first + 2 * len;
79 table->_last = table->_first + len;
82 *table->_last = (_PVFV)func;
83 table->_last++;
84 _munlock(_EXIT_LOCK1);
85 return 0;
89 /*********************************************************************
90 * _execute_onexit_table (UCRTBASE.@)
92 int __cdecl _execute_onexit_table(_onexit_table_t *table)
94 _PVFV *func;
95 _onexit_table_t copy;
97 if (!table)
98 return -1;
100 _mlock(_EXIT_LOCK1);
101 if (!table->_first || table->_first >= table->_last)
103 _munlock(_EXIT_LOCK1);
104 return 0;
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--)
115 if (*func)
116 (*func)();
119 HeapFree(GetProcessHeap(), 0, copy._first);
120 return 0;