Rev 1693 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1693 | Rev 3065 | ||
---|---|---|---|
Line 65... | Line 65... | ||
65 | #include |
65 | #include |
66 | #include "local.h" |
66 | #include "local.h" |
Line 67... | Line 67... | ||
67 | 67 | ||
Line -... | Line 68... | ||
- | 68 | /* Flush a single file, or (if fp is NULL) all files. */ |
|
- | 69 | ||
68 | /* Flush a single file, or (if fp is NULL) all files. */ |
70 | /* Core function which does not lock file pointer. This gets called |
69 | 71 | directly from __srefill. */ |
|
70 | int |
72 | int |
71 | _DEFUN(_fflush_r, (ptr, fp), |
73 | _DEFUN(__sflush_r, (ptr, fp), |
72 | struct _reent *ptr _AND |
74 | struct _reent *ptr _AND |
73 | register FILE * fp) |
75 | register FILE * fp) |
74 | { |
76 | { |
Line 75... | Line -... | ||
75 | register unsigned char *p; |
- | |
76 | register int n, t; |
- | |
77 | - | ||
78 | #ifdef _REENT_SMALL |
- | |
79 | /* For REENT_SMALL platforms, it is possible we are being |
- | |
80 | called for the first time on a std stream. This std |
- | |
81 | stream can belong to a reentrant struct that is not |
- | |
82 | _REENT. If CHECK_INIT gets called below based on _REENT, |
- | |
83 | we will end up changing said file pointers to the equivalent |
- | |
84 | std stream off of _REENT. This causes unexpected behavior if |
- | |
85 | there is any data to flush on the _REENT std stream. There |
- | |
86 | are two alternatives to fix this: 1) make a reentrant fflush |
- | |
87 | or 2) simply recognize that this file has nothing to flush |
- | |
88 | and return immediately before performing a CHECK_INIT. Choice |
- | |
89 | 2 is implemented here due to its simplicity. */ |
- | |
90 | if (fp->_bf._base == NULL) |
- | |
91 | return 0; |
- | |
92 | #endif /* _REENT_SMALL */ |
- | |
93 | - | ||
94 | CHECK_INIT (ptr, fp); |
- | |
95 | - | ||
96 | if (!fp->_flags) |
- | |
97 | return 0; |
- | |
98 | 77 | register unsigned char *p; |
|
99 | _flockfile (fp); |
78 | register int n, t; |
100 | 79 | ||
101 | t = fp->_flags; |
80 | t = fp->_flags; |
102 | if ((t & __SWR) == 0) |
81 | if ((t & __SWR) == 0) |
Line 148... | Line 127... | ||
148 | result = 0; |
127 | result = 0; |
149 | ptr->_errno = tmp_errno; |
128 | ptr->_errno = tmp_errno; |
150 | } |
129 | } |
151 | else |
130 | else |
152 | fp->_flags |= __SERR; |
131 | fp->_flags |= __SERR; |
153 | _funlockfile (fp); |
- | |
154 | return result; |
132 | return result; |
155 | } |
133 | } |
156 | } |
134 | } |
157 | if (fp->_flags & __SRD) |
135 | if (fp->_flags & __SRD) |
158 | { |
136 | { |
Line 184... | Line 162... | ||
184 | FREEUB (ptr, fp); |
162 | FREEUB (ptr, fp); |
185 | } |
163 | } |
186 | else |
164 | else |
187 | { |
165 | { |
188 | fp->_flags |= __SERR; |
166 | fp->_flags |= __SERR; |
189 | _funlockfile (fp); |
- | |
190 | return EOF; |
167 | return EOF; |
191 | } |
168 | } |
192 | } |
169 | } |
193 | _funlockfile (fp); |
- | |
194 | return 0; |
170 | return 0; |
195 | } |
171 | } |
196 | if ((p = fp->_bf._base) == NULL) |
172 | if ((p = fp->_bf._base) == NULL) |
197 | { |
173 | { |
198 | /* Nothing to flush. */ |
174 | /* Nothing to flush. */ |
199 | _funlockfile (fp); |
- | |
200 | return 0; |
175 | return 0; |
201 | } |
176 | } |
202 | n = fp->_p - p; /* write this much */ |
177 | n = fp->_p - p; /* write this much */ |
Line 203... | Line 178... | ||
203 | 178 | ||
Line 213... | Line 188... | ||
213 | { |
188 | { |
214 | t = fp->_write (ptr, fp->_cookie, (char *) p, n); |
189 | t = fp->_write (ptr, fp->_cookie, (char *) p, n); |
215 | if (t <= 0) |
190 | if (t <= 0) |
216 | { |
191 | { |
217 | fp->_flags |= __SERR; |
192 | fp->_flags |= __SERR; |
218 | _funlockfile (fp); |
- | |
219 | return EOF; |
193 | return EOF; |
220 | } |
194 | } |
221 | p += t; |
195 | p += t; |
222 | n -= t; |
196 | n -= t; |
223 | } |
197 | } |
224 | _funlockfile (fp); |
- | |
225 | return 0; |
198 | return 0; |
226 | } |
199 | } |
Line -... | Line 200... | ||
- | 200 | ||
- | 201 | int |
|
- | 202 | _DEFUN(_fflush_r, (ptr, fp), |
|
- | 203 | struct _reent *ptr _AND |
|
- | 204 | register FILE * fp) |
|
- | 205 | { |
|
- | 206 | int ret; |
|
- | 207 | ||
- | 208 | #ifdef _REENT_SMALL |
|
- | 209 | /* For REENT_SMALL platforms, it is possible we are being |
|
- | 210 | called for the first time on a std stream. This std |
|
- | 211 | stream can belong to a reentrant struct that is not |
|
- | 212 | _REENT. If CHECK_INIT gets called below based on _REENT, |
|
- | 213 | we will end up changing said file pointers to the equivalent |
|
- | 214 | std stream off of _REENT. This causes unexpected behavior if |
|
- | 215 | there is any data to flush on the _REENT std stream. There |
|
- | 216 | are two alternatives to fix this: 1) make a reentrant fflush |
|
- | 217 | or 2) simply recognize that this file has nothing to flush |
|
- | 218 | and return immediately before performing a CHECK_INIT. Choice |
|
- | 219 | 2 is implemented here due to its simplicity. */ |
|
- | 220 | if (fp->_bf._base == NULL) |
|
- | 221 | return 0; |
|
- | 222 | #endif /* _REENT_SMALL */ |
|
- | 223 | ||
- | 224 | CHECK_INIT (ptr, fp); |
|
- | 225 | ||
- | 226 | if (!fp->_flags) |
|
- | 227 | return 0; |
|
- | 228 | ||
- | 229 | _flockfile (fp); |
|
- | 230 | ret = __sflush_r (ptr, fp); |
|
- | 231 | _funlockfile (fp); |
|
- | 232 | return ret; |
|
- | 233 | } |
|
227 | 234 | ||
Line 228... | Line 235... | ||
228 | #ifndef _REENT_ONLY |
235 | #ifndef _REENT_ONLY |
229 | 236 | ||
230 | int |
237 | int |