ReactOS 0.4.15-dev-7674-gc0b4db1
atonexit.c
Go to the documentation of this file.
1
7#ifndef _DLL
8#define _DLL
9#endif
10
11#include <oscalls.h>
12#include <internal.h>
13#include <stdlib.h>
14#include <crtdefs.h>
15#include <limits.h>
16//#include <windows.h>
17
18#define _EXIT_LOCK1 8
19
20 void __cdecl _lock (int _File);
21 void __cdecl _unlock (int _File);
22
25
28
29/* INTERNAL: call atexit functions */
30void __call_atexit(void)
31{
32 /* Note: should only be called with the exit lock held */
33 _PVFV *first, *last;
34
35 if (!__onexitbegin)
36 return;
37
40
41 while (--last >= first)
42 if (*last)
43 (**last)();
44
45 free(first);
46
48}
49
50/* Choose a different name to prevent name conflicts. The CRT one works fine. */
52
54{
55 _PVFV *onexitbegin;
56 _PVFV *onexitend;
57 _onexit_t retval;
58
59#ifndef CRTDLL
60 if (__onexitbegin == (_PVFV *) -1)
61 return (* __MINGW_IMP_SYMBOL(_onexit)) (func);
62#endif
63
65
66 if (!__onexitbegin)
67 {
68 /* First time we are called. Initialize our array */
69 onexitbegin = calloc(1, sizeof(*onexitbegin));
70 if (!onexitbegin)
71 {
73 return NULL;
74 }
75 onexitend = onexitbegin;
76 }
77 else
78 {
79 onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
80 onexitend = (_PVFV *) _decode_pointer (__onexitend);
81 }
82
83 retval = __dllonexit (func, &onexitbegin, &onexitend);
84
85 if (retval != NULL)
86 {
87 /* Update our globals in case of success */
88 __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
89 __onexitend = (_PVFV *) _encode_pointer (onexitend);
90 }
91
93 return retval;
94}
95
96int __cdecl
98{
99 return (_onexit((_onexit_t)func) == NULL) ? -1 : 0;
100}
#define __MINGW_IMP_SYMBOL(sym)
Definition: _mingw_mac.h:53
#define __cdecl
Definition: accygwin.h:79
#define _EXIT_LOCK1
Definition: atonexit.c:18
void __call_atexit(void)
Definition: atonexit.c:30
void __cdecl _unlock(int _File)
Definition: lock.c:126
void __cdecl _lock(int _File)
Definition: lock.c:97
_onexit_t __cdecl __dllonexit(_onexit_t, _PVFV **, _PVFV **)
_onexit_t __cdecl _onexit(_onexit_t func)
Definition: atonexit.c:53
_PVFV * __onexitend
Definition: atonexit.c:24
_PVFV * __onexitbegin
Definition: atonexit.c:23
int __cdecl atexit(_PVFV func)
Definition: atonexit.c:97
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
GLenum func
Definition: glext.h:6028
const GLint * first
Definition: glext.h:5794
int(__cdecl * _onexit_t)(void)
Definition: stdlib.h:28
static UINT UINT last
Definition: font.c:45
#define calloc
Definition: rosglue.h:14
void *__cdecl _decode_pointer(void *)
Definition: mingw_helpers.c:19
void *__cdecl _encode_pointer(void *)
Definition: mingw_helpers.c:25
void(__cdecl * _PVFV)(void)
Definition: internal.h:33