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 * Manuel Novoa III Dec 2000
10 * Made atexit handling conform to standards... i.e. no args.
11 * Removed on_exit since it did not match gnu libc definition.
12 * Combined atexit and __do_exit into one object file.
18 #define MAXONEXIT 20 /* AIUI Posix requires 10 */
20 typedef void (*vfuncp) (void);
22 extern vfuncp __cleanup;
23 extern void __do_exit();
24 extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
26 extern vfuncp __atexit_table[MAXONEXIT];
27 extern int __atexit_count;
32 int atexit(vfuncp ptr)
34 if ((__atexit_count < 0) || (__atexit_count >= MAXONEXIT)) {
39 __cleanup = __do_exit;
40 __atexit_table[__atexit_count++] = ptr;
45 vfuncp __atexit_table[MAXONEXIT];
46 int __atexit_count = 0;
48 void __do_exit(int rv)
50 int count = __atexit_count - 1;
52 __atexit_count = -1; /* ensure no more will be added */
53 __cleanup = 0; /* Calling exit won't re-do this */
55 /* In reverse order */
56 for (; count >= 0; count--) {
57 (*__atexit_table[count])();
63 void __stdio_close_all(void); /* note: see _start.S - could be faked */