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 * Dec 2000 Manuel Novoa III
9 * Made atexit handling conform to standards... i.e. no args.
10 * Removed on_exit since it did not match gnu libc definition.
11 * Combined atexit and __do_exit into one object file.
13 * Feb 2000 Manuel Novoa III
15 * Reworked file after addition of __uClibc_main.
16 * Changed name of __do_exit to atexit_handler.
17 * Changed name of __cleanup to __uClibc_cleanup.
18 * Moved declaration of __uClibc_cleanup to __uClibc_main
19 * where it is initialized with (possibly weak alias)
27 typedef void (*vfuncp) (void);
28 extern vfuncp __uClibc_cleanup;
31 extern void __stdio_close_all(void);
33 static vfuncp __atexit_table[__UCLIBC_MAX_ATEXIT];
34 static int __atexit_count = 0;
36 static void atexit_handler(void)
41 * Guard against more functions being added and againt being reinvoked.
45 /* In reverse order */
46 for (count = __atexit_count ; count-- ; ) {
47 (*__atexit_table[count])();
52 int atexit(vfuncp ptr)
54 if ((__uClibc_cleanup == 0) || (__atexit_count >= __UCLIBC_MAX_ATEXIT)) {
59 __uClibc_cleanup = atexit_handler;
60 __atexit_table[__atexit_count++] = ptr;
69 if (__uClibc_cleanup) { /* Not already executing __uClibc_cleanup. */