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
;
40 if( __on_exit_count
< 0 || __on_exit_count
>= MAXONEXIT
)
45 __cleanup
= __do_exit
;
48 __on_exit_table
[__on_exit_count
].called
= ptr
;
49 __on_exit_table
[__on_exit_count
].argument
= 0;
63 if( __on_exit_count
< 0 || __on_exit_count
>= MAXONEXIT
)
68 __cleanup
= __do_exit
;
71 __on_exit_table
[__on_exit_count
].called
= ptr
;
72 __on_exit_table
[__on_exit_count
].argument
= arg
;
82 int __on_exit_count
= 0;
83 struct exit_table __on_exit_table
[MAXONEXIT
];
89 register int count
= __on_exit_count
-1;
91 __on_exit_count
= -1; /* ensure no more will be added */
92 __cleanup
= 0; /* Calling exit won't re-do this */
94 /* In reverse order */
95 for (; count
>= 0; count
--)
97 ptr
= __on_exit_table
[count
].called
;
98 (*ptr
) (rv
, __on_exit_table
[count
].argument
);