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

Subversion Repositories or1k

[/] [or1k/] [tags/] [tn_m001/] [newlib/] [newlib/] [libc/] [reent/] [reent.c] - Blame information for rev 861

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

Line No. Rev Author Line
1 39 lampret
/*
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-rentrant functions, such as strtok.
11
*/
12
 
13
#include <reent.h>
14
 
15
/* Interim cleanup code */
16
 
17
void
18
cleanup_glue (ptr, glue)
19
     struct _reent *ptr;
20
     struct _glue *glue;
21
{
22
  /* Have to reclaim these in reverse order: */
23
  if (glue->_next)
24
    cleanup_glue (ptr, glue->_next);
25
 
26
  _free_r (ptr, glue);
27
}
28
 
29
void
30
_reclaim_reent (ptr)
31
     struct _reent *ptr;
32
{
33
  if (ptr != _impure_ptr)
34
    {
35
      /* used by mprec routines. */
36
      if (ptr->_freelist)
37
        {
38
          int i;
39
          for (i = 0; i < 15 /* _Kmax */; i++)
40
            {
41
              struct _Bigint *thisone, *nextone;
42
 
43
              nextone = ptr->_freelist[i];
44
              while (nextone)
45
                {
46
                  thisone = nextone;
47
                  nextone = nextone->_next;
48
                  _free_r (ptr, thisone);
49
                }
50
            }
51
 
52
          _free_r (ptr, ptr->_freelist);
53
        }
54
 
55
      /* atexit stuff */
56
      if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
57
        {
58
          struct _atexit *p, *q;
59
          for (p = ptr->_atexit; p != &ptr->_atexit0;)
60
            {
61
              q = p;
62
              p = p->_next;
63
              _free_r (ptr, q);
64
            }
65
        }
66
 
67
      if (ptr->_cvtbuf)
68
        _free_r (ptr, ptr->_cvtbuf);
69
 
70
      if (ptr->__sdidinit)
71
        {
72
          /* cleanup won't reclaim memory 'coz usually it's run
73
             before the program exits, and who wants to wait for that? */
74
          ptr->__cleanup (ptr);
75
 
76
          if (ptr->__sglue._next)
77
            cleanup_glue (ptr, ptr->__sglue._next);
78
        }
79
 
80
      /* Malloc memory not reclaimed; no good way to return memory anyway. */
81
 
82
    }
83
}
84
 
85
/*
86
 *  Do atexit() processing and cleanup
87
 *
88
 *  NOTE:  This is to be executed at task exit.  It does not tear anything
89
 *         down which is used on a global basis.
90
 */
91
 
92
void
93
_wrapup_reent(struct _reent *ptr)
94
{
95
  register struct _atexit *p;
96
  register int n;
97
 
98
  if (ptr == 0)
99
      ptr = _REENT;
100
 
101
  for (p = ptr->_atexit; p; p = p->_next)
102
    for (n = p->_ind; --n >= 0;)
103
      (*p->_fns[n]) ();
104
  if (ptr->__cleanup)
105
    (*ptr->__cleanup) (ptr);
106
}
107
 

powered by: WebSVN 2.1.0

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