summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdlib/exit.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2003-06-06 15:36:31 +0000
committerNick Clifton <nickc@redhat.com>2003-06-06 15:36:31 +0000
commit75d7d177004358ba5e410a2cd98f2249b6c4e1b3 (patch)
treefc1541e54ea04ed5a4260fbc60e578424945e2ef /newlib/libc/stdlib/exit.c
parent54152c7e7ed656c969fe4536f17f66360cd8d971 (diff)
downloadcygnal-75d7d177004358ba5e410a2cd98f2249b6c4e1b3.tar.gz
cygnal-75d7d177004358ba5e410a2cd98f2249b6c4e1b3.tar.bz2
cygnal-75d7d177004358ba5e410a2cd98f2249b6c4e1b3.zip
New structure containing fields used by the on_exit() function.
(struct _atexit): Include struct _on_exit_args. For _REENT_SMALL do his via a pointer that is initialised when needed.
Diffstat (limited to 'newlib/libc/stdlib/exit.c')
-rw-r--r--newlib/libc/stdlib/exit.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/newlib/libc/stdlib/exit.c b/newlib/libc/stdlib/exit.c
index 54664fec5..a659361bd 100644
--- a/newlib/libc/stdlib/exit.c
+++ b/newlib/libc/stdlib/exit.c
@@ -60,20 +60,43 @@ _DEFUN (exit, (code),
int code)
{
register struct _atexit *p;
+ register struct _on_exit_args * args;
register int n;
- int i = 1;
+ int i;
+
+ p = &_REENT->_atexit;
#ifdef _REENT_SMALL
- for (p = &_REENT->_atexit, n = p->_ind-1, i = (n>=0) ? (1<<n) : 0;
- n >= 0; --n, i >>= 1)
+ args = p->_on_exit_args_ptr;
+
+ if (args == NULL)
+ {
+ for (n = p->_ind; n--;)
+ p->_fns[n] ();
+ }
+ else
+ {
+ for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+ if (args->_fntypes & i)
+ (*((void (*)(int, void *)) p->_fns[n]))(code, args->_fnargs[n]);
+ else
+ p->_fns[n] ();
+ }
#else
- for (p = _REENT->_atexit; p; p = p->_next)
- for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+ do
+ {
+ args = & p->_on_exit_args;
+
+ for (n = p->_ind - 1, i = (n >= 0) ? (1 << n) : 0; n >= 0; --n, i >>= 1)
+ if (args->_fntypes & i)
+ (*((void (*)(int, void *)) p->_fns[n]))(code, args->_fnargs[n]);
+ else
+ p->_fns[n] ();
+
+ p = p->_next;
+ }
+ while (p);
#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);