From 75d7d177004358ba5e410a2cd98f2249b6c4e1b3 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Fri, 6 Jun 2003 15:36:31 +0000 Subject: 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. --- newlib/libc/stdlib/exit.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'newlib/libc/stdlib/exit.c') 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<= 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); -- cgit v1.2.3