1 /* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
2 * This file is part of the Linux-8086 C library and is distributed
3 * under the GNU Library General Public License.
7 * This deals with both the atexit and on_exit function calls
9 * Note calls installed with atexit are called with the same args as on_exit
10 * fuctions; the void* is given the NULL value.
17 #define MAXONEXIT 20 /* AIUI Posix requires 10 */
19 typedef void (*vfuncp) ();
21 extern vfuncp __cleanup;
22 extern void __do_exit();
24 extern struct exit_table
29 __on_exit_table[MAXONEXIT];
31 extern int __on_exit_count;
42 if( __on_exit_count < 0 || __on_exit_count >= MAXONEXIT)
47 __cleanup = __do_exit;
50 __on_exit_table[__on_exit_count].called = ptr;
51 __on_exit_table[__on_exit_count].argument = 0;
65 if( __on_exit_count < 0 || __on_exit_count >= MAXONEXIT)
70 __cleanup = __do_exit;
73 __on_exit_table[__on_exit_count].called = ptr;
74 __on_exit_table[__on_exit_count].argument = arg;
84 int __on_exit_count = 0;
85 struct exit_table __on_exit_table[MAXONEXIT];
91 register int count = __on_exit_count-1;
93 __on_exit_count = -1; /* ensure no more will be added */
94 __cleanup = 0; /* Calling exit won't re-do this */
96 /* In reverse order */
97 for (; count >= 0; count--)
99 ptr = __on_exit_table[count].called;
100 (*ptr) (rv, __on_exit_table[count].argument);