OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [reent/] [reent.c] - Blame information for rev 362

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
FUNCTION
3
        <<reent>>---definition of impure data.
4
 
5
INDEX
6
        reent
7
 
8
DESCRIPTION
9
        This module defines the impure data area used by the
10
        non-reentrant functions, such as strtok.
11
*/
12
 
13
#include <stdlib.h>
14
#include <reent.h>
15
 
16
#ifdef _REENT_ONLY
17
#ifndef REENTRANT_SYSCALLS_PROVIDED
18
#define REENTRANT_SYSCALLS_PROVIDED
19
#endif
20
#endif
21
 
22
#ifndef REENTRANT_SYSCALLS_PROVIDED
23
 
24
/* We use the errno variable used by the system dependent layer.  */
25
#undef errno
26
int errno;
27
 
28
#endif
29
 
30
/* Interim cleanup code */
31
 
32
void
33
_DEFUN (cleanup_glue, (ptr, glue),
34
     struct _reent *ptr _AND
35
     struct _glue *glue)
36
{
37
  /* Have to reclaim these in reverse order: */
38
  if (glue->_next)
39
    cleanup_glue (ptr, glue->_next);
40
 
41
  _free_r (ptr, glue);
42
}
43
 
44
void
45
_DEFUN (_reclaim_reent, (ptr),
46
     struct _reent *ptr)
47
{
48
  if (ptr != _impure_ptr)
49
    {
50
      /* used by mprec routines. */
51
#ifdef _REENT_SMALL
52
      if (ptr->_mp)     /* don't bother allocating it! */
53
      {
54
#endif
55
      if (_REENT_MP_FREELIST(ptr))
56
        {
57
          int i;
58
          for (i = 0; i < _Kmax; i++)
59
            {
60
              struct _Bigint *thisone, *nextone;
61
 
62
              nextone = _REENT_MP_FREELIST(ptr)[i];
63
              while (nextone)
64
                {
65
                  thisone = nextone;
66
                  nextone = nextone->_next;
67
                  _free_r (ptr, thisone);
68
                }
69
            }
70
 
71
          _free_r (ptr, _REENT_MP_FREELIST(ptr));
72
        }
73
      if (_REENT_MP_RESULT(ptr))
74
        _free_r (ptr, _REENT_MP_RESULT(ptr));
75
#ifdef _REENT_SMALL
76
      }
77
#endif
78
 
79
#ifdef _REENT_SMALL
80
      if (ptr->_emergency)
81
        _free_r (ptr, ptr->_emergency);
82
      if (ptr->_mp)
83
        _free_r (ptr, ptr->_mp);
84
      if (ptr->_r48)
85
        _free_r (ptr, ptr->_r48);
86
      if (ptr->_localtime_buf)
87
        _free_r (ptr, ptr->_localtime_buf);
88
      if (ptr->_asctime_buf)
89
        _free_r (ptr, ptr->_asctime_buf);
90
      if (ptr->_atexit && ptr->_atexit->_on_exit_args_ptr)
91
        _free_r (ptr, ptr->_atexit->_on_exit_args_ptr);
92
#else
93
      /* atexit stuff */
94
      if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
95
        {
96
          struct _atexit *p, *q;
97
          for (p = ptr->_atexit; p != &ptr->_atexit0;)
98
            {
99
              q = p;
100
              p = p->_next;
101
              _free_r (ptr, q);
102
            }
103
        }
104
#endif
105
 
106
      if (ptr->_cvtbuf)
107
        _free_r (ptr, ptr->_cvtbuf);
108
 
109
      if (ptr->__sdidinit)
110
        {
111
          /* cleanup won't reclaim memory 'coz usually it's run
112
             before the program exits, and who wants to wait for that? */
113
          ptr->__cleanup (ptr);
114
 
115
          if (ptr->__sglue._next)
116
            cleanup_glue (ptr, ptr->__sglue._next);
117
        }
118
 
119
      /* Malloc memory not reclaimed; no good way to return memory anyway. */
120
 
121
    }
122
}
123
 
124
/*
125
 *  Do atexit() processing and cleanup
126
 *
127
 *  NOTE:  This is to be executed at task exit.  It does not tear anything
128
 *         down which is used on a global basis.
129
 */
130
 
131
void
132
_DEFUN (_wrapup_reent, (ptr), struct _reent *ptr)
133
{
134
  register struct _atexit *p;
135
  register int n;
136
 
137
  if (ptr == NULL)
138
    ptr = _REENT;
139
 
140
#ifdef _REENT_SMALL
141
  for (p = ptr->_atexit, n = p ? p->_ind : 0; --n >= 0;)
142
    (*p->_fns[n]) ();
143
#else
144
  for (p = ptr->_atexit; p; p = p->_next)
145
    for (n = p->_ind; --n >= 0;)
146
      (*p->_fns[n]) ();
147
#endif
148
  if (ptr->__cleanup)
149
    (*ptr->__cleanup) (ptr);
150
}
151
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.