aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/stdlib/exit.c
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2002-05-15 22:58:10 +0000
committerJeff Johnston <jjohnstn@redhat.com>2002-05-15 22:58:10 +0000
commitdc824ef7363e46b3602b458f7bf00303601c1102 (patch)
treee323a2db83cf227cf6ddd465d8657d9339d15369 /newlib/libc/stdlib/exit.c
parente355de817c95c1b5b3fa98c0e5e2863a1ecb7679 (diff)
downloadnewlib-dc824ef7363e46b3602b458f7bf00303601c1102.zip
newlib-dc824ef7363e46b3602b458f7bf00303601c1102.tar.gz
newlib-dc824ef7363e46b3602b458f7bf00303601c1102.tar.bz2
2002-05-15 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/stdlib.h: Add on_exit prototype. * libc/include/sys/reent.h (struct _atexit): Add argument array and bits to track type of exit routine to support both on_exit and atexit. (_REENT_INIT_PTR): Add missing fields that won't be zeroed out by default and change the setting of the atexit structure. (_REENT_INIT)[!_REENT_SMALL]: Remove extraneous end brace. * libc/stdlib/on_exit.c: New file. * libc/stdlib/Makefile.am: Add support for on_exit. * libc/stdlib/Makefile.in: Regenerated. * libc/stdlib/atexit.c: Change to initialize types field. * libc/stdlib/exit.c: Change to look at types field for each exit routine and either call an atexit-style or an on_exit-style routine accordingly.
Diffstat (limited to 'newlib/libc/stdlib/exit.c')
-rw-r--r--newlib/libc/stdlib/exit.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/newlib/libc/stdlib/exit.c b/newlib/libc/stdlib/exit.c
index fb7f73e..54664fe 100644
--- a/newlib/libc/stdlib/exit.c
+++ b/newlib/libc/stdlib/exit.c
@@ -61,15 +61,20 @@ _DEFUN (exit, (code),
{
register struct _atexit *p;
register int n;
+ int i = 1;
#ifdef _REENT_SMALL
- for (p = &_REENT->_atexit, n = p->_ind; --n >= 0;)
- (*p->_fns[n]) ();
+ for (p = &_REENT->_atexit, n = p->_ind-1, i = (n>=0) ? (1<<n) : 0;
+ n >= 0; --n, i >>= 1)
#else
for (p = _REENT->_atexit; p; p = p->_next)
- for (n = p->_ind; --n >= 0;)
- (*p->_fns[n]) ();
+ for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
#endif
+ if (p->_fntypes & i)
+ (*((void (*)(int, void *))p->_fns[n]))(code, p->_fnargs[n]);
+ else
+ (*p->_fns[n]) ();
+
if (_REENT->__cleanup)
(*_REENT->__cleanup) (_REENT);
_exit (code);