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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [reent/] [reent.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/*
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
cleanup_glue (ptr, glue)
34
     struct _reent *ptr;
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
_reclaim_reent (ptr)
46
     struct _reent *ptr;
47
{
48
  if (ptr != _impure_ptr)
49
    {
50
      /* used by mprec routines. */
51
      if (ptr->_freelist)
52
        {
53
          int i;
54
          for (i = 0; i < 15 /* _Kmax */; i++)
55
            {
56
              struct _Bigint *thisone, *nextone;
57
 
58
              nextone = ptr->_freelist[i];
59
              while (nextone)
60
                {
61
                  thisone = nextone;
62
                  nextone = nextone->_next;
63
                  _free_r (ptr, thisone);
64
                }
65
            }
66
 
67
          _free_r (ptr, ptr->_freelist);
68
        }
69
 
70
      /* atexit stuff */
71
      if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
72
        {
73
          struct _atexit *p, *q;
74
          for (p = ptr->_atexit; p != &ptr->_atexit0;)
75
            {
76
              q = p;
77
              p = p->_next;
78
              _free_r (ptr, q);
79
            }
80
        }
81
 
82
      if (ptr->_cvtbuf)
83
        _free_r (ptr, ptr->_cvtbuf);
84
 
85
      if (ptr->__sdidinit)
86
        {
87
          /* cleanup won't reclaim memory 'coz usually it's run
88
             before the program exits, and who wants to wait for that? */
89
          ptr->__cleanup (ptr);
90
 
91
          if (ptr->__sglue._next)
92
            cleanup_glue (ptr, ptr->__sglue._next);
93
        }
94
 
95
      /* Malloc memory not reclaimed; no good way to return memory anyway. */
96
 
97
    }
98
}
99
 
100
/*
101
 *  Do atexit() processing and cleanup
102
 *
103
 *  NOTE:  This is to be executed at task exit.  It does not tear anything
104
 *         down which is used on a global basis.
105
 */
106
 
107
void
108
_wrapup_reent(struct _reent *ptr)
109
{
110
  register struct _atexit *p;
111
  register int n;
112
 
113
  if (ptr == 0)
114
      ptr = _REENT;
115
 
116
  for (p = ptr->_atexit; p; p = p->_next)
117
    for (n = p->_ind; --n >= 0;)
118
      (*p->_fns[n]) ();
119
  if (ptr->__cleanup)
120
    (*ptr->__cleanup) (ptr);
121
}
122
 

powered by: WebSVN 2.1.0

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