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

Subversion Repositories openrisc_me

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

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

Line No. Rev Author Line
1 148 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
#endif
54
      if (_REENT_MP_FREELIST(ptr))
55
        {
56
          int i;
57
          for (i = 0; i < 15 /* _Kmax */; i++)
58
            {
59
              struct _Bigint *thisone, *nextone;
60
 
61
              nextone = _REENT_MP_FREELIST(ptr)[i];
62
              while (nextone)
63
                {
64
                  thisone = nextone;
65
                  nextone = nextone->_next;
66
                  _free_r (ptr, thisone);
67
                }
68
            }
69
 
70
          _free_r (ptr, _REENT_MP_FREELIST(ptr));
71
        }
72
      if (_REENT_MP_RESULT(ptr))
73
        _free_r (ptr, _REENT_MP_RESULT(ptr));
74
 
75
#ifdef _REENT_SMALL
76
      if (ptr->_emergency)
77
        _free_r (ptr, ptr->_emergency);
78
      if (ptr->_mp)
79
        _free_r (ptr, ptr->_mp);
80
      if (ptr->_r48)
81
        _free_r (ptr, ptr->_r48);
82
      if (ptr->_localtime_buf)
83
        _free_r (ptr, ptr->_localtime_buf);
84
      if (ptr->_asctime_buf)
85
        _free_r (ptr, ptr->_asctime_buf);
86
      if (ptr->_atexit->_on_exit_args_ptr)
87
        _free_r (ptr, ptr->_atexit->_on_exit_args_ptr);
88
#else
89
      /* atexit stuff */
90
      if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
91
        {
92
          struct _atexit *p, *q;
93
          for (p = ptr->_atexit; p != &ptr->_atexit0;)
94
            {
95
              q = p;
96
              p = p->_next;
97
              _free_r (ptr, q);
98
            }
99
        }
100
#endif
101
 
102
      if (ptr->_cvtbuf)
103
        _free_r (ptr, ptr->_cvtbuf);
104
 
105
      if (ptr->__sdidinit)
106
        {
107
          /* cleanup won't reclaim memory 'coz usually it's run
108
             before the program exits, and who wants to wait for that? */
109
          ptr->__cleanup (ptr);
110
 
111
          if (ptr->__sglue._next)
112
            cleanup_glue (ptr, ptr->__sglue._next);
113
        }
114
 
115
      /* Malloc memory not reclaimed; no good way to return memory anyway. */
116
 
117
    }
118
}
119
 
120
/*
121
 *  Do atexit() processing and cleanup
122
 *
123
 *  NOTE:  This is to be executed at task exit.  It does not tear anything
124
 *         down which is used on a global basis.
125
 */
126
 
127
void
128
_DEFUN (_wrapup_reent, (ptr), struct _reent *ptr)
129
{
130
  register struct _atexit *p;
131
  register int n;
132
 
133
  if (ptr == 0)
134
      ptr = _REENT;
135
 
136
#ifdef _REENT_SMALL
137
  for (p = &ptr->_atexit, n = p->_ind; --n >= 0;)
138
    (*p->_fns[n]) ();
139
#else
140
  for (p = ptr->_atexit; p; p = p->_next)
141
    for (n = p->_ind; --n >= 0;)
142
      (*p->_fns[n]) ();
143
#endif
144
  if (ptr->__cleanup)
145
    (*ptr->__cleanup) (ptr);
146
}
147
 

powered by: WebSVN 2.1.0

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