Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdlib/atexit.c')
-rw-r--r--newlib/libc/stdlib/atexit.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/newlib/libc/stdlib/atexit.c b/newlib/libc/stdlib/atexit.c
index 21ffd6e7b..88cdd234c 100644
--- a/newlib/libc/stdlib/atexit.c
+++ b/newlib/libc/stdlib/atexit.c
@@ -50,8 +50,9 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
+#include <stddef.h>
#include <stdlib.h>
-#include "atexit.h"
+#include <reent.h>
/*
* Register a function to be performed at exit.
@@ -62,5 +63,18 @@ _DEFUN (atexit,
(fn),
_VOID _EXFUN ((*fn), (_VOID)))
{
- return __register_exitproc (__et_atexit, fn, NULL, NULL);
+ register struct _atexit *p;
+
+ if ((p = _REENT->_atexit) == NULL)
+ _REENT->_atexit = p = &_REENT->_atexit0;
+ if (p->_ind >= _ATEXIT_SIZE)
+ {
+ if ((p = (struct _atexit *) malloc (sizeof *p)) == NULL)
+ return -1;
+ p->_ind = 0;
+ p->_next = _REENT->_atexit;
+ _REENT->_atexit = p;
+ }
+ p->_fns[p->_ind++] = fn;
+ return 0;
}