summaryrefslogtreecommitdiff
path: root/libc/stdlib/atexit.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/atexit.c')
-rw-r--r--libc/stdlib/atexit.c49
1 files changed, 17 insertions, 32 deletions
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index 5079692af..a7ec0fb1f 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -12,45 +12,17 @@
* Combined atexit and __do_exit into one object file.
*/
+#include <stdlib.h>
#include <errno.h>
-/* ATEXIT.H */
-
-/*
- * NOTE!!! The following should match the value returned by
- * by sysconf(_SC_ATEXIT_MAX) in unistd/sysconf.c
- */
-#define MAXATEXIT 20 /* AIUI Posix requires 10 */
-
typedef void (*vfuncp) (void);
-
extern vfuncp __cleanup;
-extern void __do_exit();
-extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
-
-extern vfuncp __atexit_table[MAXATEXIT];
-extern int __atexit_count;
-
-/* End ATEXIT.H */
#ifdef L_atexit
-int atexit(vfuncp ptr)
-{
- if ((__atexit_count < 0) || (__atexit_count >= MAXATEXIT)) {
- errno = ENOMEM;
- return -1;
- }
- if (ptr) {
- __cleanup = __do_exit;
- __atexit_table[__atexit_count++] = ptr;
- }
- return 0;
-}
+static vfuncp __atexit_table[__UCLIBC_MAX_ATEXIT];
+static int __atexit_count = 0;
-vfuncp __atexit_table[MAXATEXIT];
-int __atexit_count = 0;
-
-void __do_exit(int rv)
+static void __do_exit(void)
{
int count = __atexit_count - 1;
@@ -62,6 +34,19 @@ void __do_exit(int rv)
(*__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