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 typedef void (*vfuncp) (void);
19 extern vfuncp __cleanup;
22 static vfuncp __atexit_table[__UCLIBC_MAX_ATEXIT];
23 static int __atexit_count = 0;
25 static void __do_exit(void)
27 int count = __atexit_count - 1;
29 __atexit_count = -1; /* ensure no more will be added */
30 __cleanup = 0; /* Calling exit won't re-do this */
32 /* In reverse order */
33 for (; count >= 0; count--) {
34 (*__atexit_table[count])();
38 int atexit(vfuncp ptr)
40 if ((__atexit_count < 0) || (__atexit_count >= __UCLIBC_MAX_ATEXIT)) {
45 __cleanup = __do_exit;
46 __atexit_table[__atexit_count++] = ptr;