Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / reent / reent.c
blob74503fa592916cfc1432a9c8c2c063fb3cd7ae79
1 /*
2 FUNCTION
3 <<reent>>---definition of impure data.
5 INDEX
6 reent
8 DESCRIPTION
9 This module defines the impure data area used by the
10 non-reentrant functions, such as strtok.
13 #include <stdlib.h>
14 #include <reent.h>
16 #ifdef _REENT_ONLY
17 #ifndef REENTRANT_SYSCALLS_PROVIDED
18 #define REENTRANT_SYSCALLS_PROVIDED
19 #endif
20 #endif
22 #ifndef REENTRANT_SYSCALLS_PROVIDED
24 /* We use the errno variable used by the system dependent layer. */
25 #undef errno
26 int errno;
28 #endif
30 void
31 _reclaim_reent (struct _reent *ptr)
33 #ifndef _REENT_THREAD_LOCAL
34 if (ptr != _impure_ptr)
35 #endif
37 /* used by mprec routines. */
38 #ifdef _REENT_SMALL
39 if (ptr->_mp) /* don't bother allocating it! */
41 #endif
42 if (_REENT_MP_FREELIST(ptr))
44 int i;
45 for (i = 0; i < _Kmax; i++)
47 struct _Bigint *thisone, *nextone;
49 nextone = _REENT_MP_FREELIST(ptr)[i];
50 while (nextone)
52 thisone = nextone;
53 nextone = nextone->_next;
54 _free_r (ptr, thisone);
58 _free_r (ptr, _REENT_MP_FREELIST(ptr));
60 if (_REENT_MP_RESULT(ptr))
61 _free_r (ptr, _REENT_MP_RESULT(ptr));
62 if (_REENT_MP_P5S(ptr))
64 struct _Bigint *thisone, *nextone;
65 nextone = _REENT_MP_P5S(ptr);
66 while (nextone)
68 thisone = nextone;
69 nextone = nextone->_next;
70 _free_r (ptr, thisone);
73 #ifdef _REENT_SMALL
75 #endif
77 #ifdef _REENT_SMALL
78 if (_REENT_EMERGENCY(ptr))
79 _free_r (ptr, _REENT_EMERGENCY(ptr));
80 if (ptr->_mp)
81 _free_r (ptr, ptr->_mp);
82 if (ptr->_r48)
83 _free_r (ptr, ptr->_r48);
84 if (ptr->_localtime_buf)
85 _free_r (ptr, ptr->_localtime_buf);
86 if (ptr->_asctime_buf)
87 _free_r (ptr, ptr->_asctime_buf);
88 if (ptr->_signal_buf)
89 _free_r (ptr, ptr->_signal_buf);
90 if (ptr->_misc)
91 _free_r (ptr, ptr->_misc);
92 #endif
94 if (_REENT_CVTBUF(ptr))
95 _free_r (ptr, _REENT_CVTBUF(ptr));
96 /* We should free _sig_func to avoid a memory leak, but how to
97 do it safely considering that a signal may be delivered immediately
98 after the free?
99 if (_REENT_SIG_FUNC(ptr))
100 _free_r (ptr, _REENT_SIG_FUNC(ptr));*/
102 if (_REENT_CLEANUP(ptr))
104 /* cleanup won't reclaim memory 'coz usually it's run
105 before the program exits, and who wants to wait for that? */
106 _REENT_CLEANUP(ptr) (ptr);
109 /* Malloc memory not reclaimed; no good way to return memory anyway. */