/* Copyright (C) 1995,1996 Robert de Bath * This file is part of the Linux-8086 C library and is distributed * under the GNU Library General Public License. */ /* * Manuel Novoa III Dec 2000 * * Modifications: * Made atexit handling conform to standards... i.e. no args. * Removed on_exit since it did not match gnu libc definition. * Combined atexit and __do_exit into one object file. */ #include #include typedef void (*vfuncp) (void); extern vfuncp __cleanup; #ifdef L_atexit static vfuncp __atexit_table[__UCLIBC_MAX_ATEXIT]; static int __atexit_count = 0; static void __do_exit(void) { int count = __atexit_count - 1; __atexit_count = -1; /* ensure no more will be added */ __cleanup = 0; /* Calling exit won't re-do this */ /* In reverse order */ for (; count >= 0; count--) { (*__atexit_table[count])(); } } int atexit(vfuncp ptr) { if ((__atexit_count < 0) || (__atexit_count >= __UCLIBC_MAX_ATEXIT)) { errno = ENOMEM; return -1; } if (ptr) { __cleanup = __do_exit; __atexit_table[__atexit_count++] = ptr; } return 0; } #endif #ifdef L_exit void __stdio_close_all(void); /* note: see _start.S - could be faked */ vfuncp __cleanup = 0; void exit(int rv) { if (__cleanup) __cleanup(); __stdio_close_all(); _exit(rv); } #endif