Rev 4874 | Rev 6099 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
Line 60... | Line 60... | ||
60 | ptr->_write = __swrite64; |
60 | ptr->_write = __swrite64; |
61 | ptr->_seek64 = __sseek64; |
61 | ptr->_seek64 = __sseek64; |
62 | ptr->_flags |= __SL64; |
62 | ptr->_flags |= __SL64; |
63 | #endif /* __LARGE64_FILES */ |
63 | #endif /* __LARGE64_FILES */ |
64 | ptr->_seek = __sseek; |
64 | ptr->_seek = __sseek; |
- | 65 | #ifdef _STDIO_CLOSE_PER_REENT_STD_STREAMS |
|
65 | ptr->_close = __sclose; |
66 | ptr->_close = __sclose; |
- | 67 | #else /* _STDIO_CLOSE_STD_STREAMS */ |
|
- | 68 | ptr->_close = NULL; |
|
- | 69 | #endif /* _STDIO_CLOSE_STD_STREAMS */ |
|
66 | #if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) |
70 | #if !defined(__SINGLE_THREAD__) && !defined(_REENT_SMALL) |
67 | __lock_init_recursive (ptr->_lock); |
71 | __lock_init_recursive (ptr->_lock); |
68 | /* |
72 | /* |
69 | * #else |
73 | * #else |
70 | * lock is already initialized in __sfp |
74 | * lock is already initialized in __sfp |
Line 75... | Line 79... | ||
75 | if (__stextmode (ptr->_file)) |
79 | if (__stextmode (ptr->_file)) |
76 | ptr->_flags |= __SCLE; |
80 | ptr->_flags |= __SCLE; |
77 | #endif |
81 | #endif |
78 | } |
82 | } |
Line -... | Line 83... | ||
- | 83 | ||
- | 84 | struct glue_with_file { |
|
- | 85 | struct _glue glue; |
|
- | 86 | FILE file; |
|
- | 87 | }; |
|
79 | 88 | ||
80 | struct _glue * |
89 | struct _glue * |
81 | _DEFUN(__sfmoreglue, (d, n), |
90 | _DEFUN(__sfmoreglue, (d, n), |
82 | struct _reent *d _AND |
91 | struct _reent *d _AND |
83 | register int n) |
92 | register int n) |
84 | { |
93 | { |
85 | struct _glue *g; |
- | |
Line -... | Line 94... | ||
- | 94 | struct glue_with_file *g; |
|
86 | FILE *p; |
95 | |
87 | 96 | g = (struct glue_with_file *) |
|
88 | g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE)); |
97 | _malloc_r (d, sizeof (*g) + (n - 1) * sizeof (FILE)); |
89 | if (g == NULL) |
- | |
90 | return NULL; |
98 | if (g == NULL) |
91 | p = (FILE *) (g + 1); |
99 | return NULL; |
92 | g->_next = NULL; |
100 | g->glue._next = NULL; |
93 | g->_niobs = n; |
101 | g->glue._niobs = n; |
94 | g->_iobs = p; |
102 | g->glue._iobs = &g->file; |
95 | memset (p, 0, n * sizeof (FILE)); |
103 | memset (&g->file, 0, n * sizeof (FILE)); |
Line 96... | Line 104... | ||
96 | return g; |
104 | return &g->glue; |
97 | } |
105 | } |
98 | 106 | ||
Line 106... | Line 114... | ||
106 | { |
114 | { |
107 | FILE *fp; |
115 | FILE *fp; |
108 | int n; |
116 | int n; |
109 | struct _glue *g; |
117 | struct _glue *g; |
Line 110... | Line 118... | ||
110 | 118 | ||
Line 111... | Line 119... | ||
111 | __sfp_lock_acquire (); |
119 | _newlib_sfp_lock_start (); |
112 | 120 | ||
113 | if (!_GLOBAL_REENT->__sdidinit) |
121 | if (!_GLOBAL_REENT->__sdidinit) |
114 | __sinit (_GLOBAL_REENT); |
122 | __sinit (_GLOBAL_REENT); |
Line 119... | Line 127... | ||
119 | goto found; |
127 | goto found; |
120 | if (g->_next == NULL && |
128 | if (g->_next == NULL && |
121 | (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) |
129 | (g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) |
122 | break; |
130 | break; |
123 | } |
131 | } |
124 | __sfp_lock_release (); |
132 | _newlib_sfp_lock_exit (); |
125 | d->_errno = ENOMEM; |
133 | d->_errno = ENOMEM; |
126 | return NULL; |
134 | return NULL; |
Line 127... | Line 135... | ||
127 | 135 | ||
128 | found: |
136 | found: |
129 | fp->_file = -1; /* no file */ |
137 | fp->_file = -1; /* no file */ |
130 | fp->_flags = 1; /* reserve this slot; caller sets real flags */ |
138 | fp->_flags = 1; /* reserve this slot; caller sets real flags */ |
131 | fp->_flags2 = 0; |
139 | fp->_flags2 = 0; |
132 | #ifndef __SINGLE_THREAD__ |
140 | #ifndef __SINGLE_THREAD__ |
133 | __lock_init_recursive (fp->_lock); |
141 | __lock_init_recursive (fp->_lock); |
134 | #endif |
142 | #endif |
Line 135... | Line 143... | ||
135 | __sfp_lock_release (); |
143 | _newlib_sfp_lock_end (); |
136 | 144 | ||
137 | fp->_p = NULL; /* no current pointer */ |
145 | fp->_p = NULL; /* no current pointer */ |
138 | fp->_w = 0; /* nothing to read or write */ |
146 | fp->_w = 0; /* nothing to read or write */ |
Line 190... | Line 198... | ||
190 | return; |
198 | return; |
191 | } |
199 | } |
Line 192... | Line 200... | ||
192 | 200 | ||
193 | /* make sure we clean up on exit */ |
201 | /* make sure we clean up on exit */ |
194 | s->__cleanup = _cleanup_r; /* conservative */ |
- | |
Line 195... | Line 202... | ||
195 | s->__sdidinit = 1; |
202 | s->__cleanup = _cleanup_r; /* conservative */ |
196 | 203 | ||
197 | s->__sglue._next = NULL; |
204 | s->__sglue._next = NULL; |
198 | #ifndef _REENT_SMALL |
205 | #ifndef _REENT_SMALL |
199 | s->__sglue._niobs = 3; |
206 | s->__sglue._niobs = 3; |
200 | s->__sglue._iobs = &s->__sf[0]; |
207 | s->__sglue._iobs = &s->__sf[0]; |
201 | #else |
208 | #else |
- | 209 | s->__sglue._niobs = 0; |
|
- | 210 | s->__sglue._iobs = NULL; |
|
- | 211 | /* Avoid infinite recursion when calling __sfp for _GLOBAL_REENT. The |
|
- | 212 | problem is that __sfp checks for _GLOBAL_REENT->__sdidinit and calls |
|
- | 213 | __sinit if it's 0. */ |
|
202 | s->__sglue._niobs = 0; |
214 | if (s == _GLOBAL_REENT) |
203 | s->__sglue._iobs = NULL; |
215 | s->__sdidinit = 1; |
204 | s->_stdin = __sfp(s); |
216 | s->_stdin = __sfp(s); |
205 | s->_stdout = __sfp(s); |
217 | s->_stdout = __sfp(s); |
Line 222... | Line 234... | ||
222 | 234 | ||
223 | /* POSIX requires stderr to be opened for reading and writing, even |
235 | /* POSIX requires stderr to be opened for reading and writing, even |
224 | when the underlying fd 2 is write-only. */ |
236 | when the underlying fd 2 is write-only. */ |
Line -... | Line 237... | ||
- | 237 | std (s->_stderr, __SRW | __SNBF, 2, s); |
|
- | 238 | ||
225 | std (s->_stderr, __SRW | __SNBF, 2, s); |
239 | s->__sdidinit = 1; |
226 | 240 | ||
Line 227... | Line 241... | ||
227 | __sinit_lock_release (); |
241 | __sinit_lock_release (); |
Line 233... | Line 247... | ||
233 | __LOCK_INIT_RECURSIVE(static, __sinit_lock); |
247 | __LOCK_INIT_RECURSIVE(static, __sinit_lock); |
Line 234... | Line 248... | ||
234 | 248 | ||
235 | _VOID |
249 | _VOID |
236 | _DEFUN_VOID(__sfp_lock_acquire) |
250 | _DEFUN_VOID(__sfp_lock_acquire) |
237 | { |
251 | { |
238 | __lock_acquire_recursive (__sfp_lock); |
252 | //__lock_acquire_recursive (__sfp_lock); |
Line 239... | Line 253... | ||
239 | } |
253 | } |
240 | 254 | ||
241 | _VOID |
255 | _VOID |
242 | _DEFUN_VOID(__sfp_lock_release) |
256 | _DEFUN_VOID(__sfp_lock_release) |
243 | { |
257 | { |
Line 244... | Line 258... | ||
244 | __lock_release_recursive (__sfp_lock); |
258 | //__lock_release_recursive (__sfp_lock); |
245 | } |
259 | } |
246 | 260 | ||
247 | _VOID |
261 | _VOID |
248 | _DEFUN_VOID(__sinit_lock_acquire) |
262 | _DEFUN_VOID(__sinit_lock_acquire) |
Line 249... | Line 263... | ||
249 | { |
263 | { |
250 | __lock_acquire_recursive (__sinit_lock); |
264 | //__lock_acquire_recursive (__sinit_lock); |
251 | } |
265 | } |
252 | 266 | ||
253 | _VOID |
267 | _VOID |
Line 254... | Line 268... | ||
254 | _DEFUN_VOID(__sinit_lock_release) |
268 | _DEFUN_VOID(__sinit_lock_release) |
255 | { |
269 | { |
256 | __lock_release_recursive (__sinit_lock); |
270 | //__lock_release_recursive (__sinit_lock); |