summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdio/refill.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/refill.c')
-rw-r--r--newlib/libc/stdio/refill.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c
index 27266ce70..9d853f94d 100644
--- a/newlib/libc/stdio/refill.c
+++ b/newlib/libc/stdio/refill.c
@@ -102,9 +102,19 @@ _DEFUN(__srefill_r, (ptr, fp),
* flush all line buffered output files, per the ANSI C
* standard.
*/
-
if (fp->_flags & (__SLBF | __SNBF))
- _CAST_VOID _fwalk (_GLOBAL_REENT, lflush);
+ {
+ /* Ignore this file in _fwalk to avoid potential deadlock. */
+ short orig_flags = fp->_flags;
+ fp->_flags = 1;
+ _CAST_VOID _fwalk (_GLOBAL_REENT, lflush);
+ fp->_flags = orig_flags;
+
+ /* Now flush this file without locking it. */
+ if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
+ __sflush_r (ptr, fp);
+ }
+
fp->_p = fp->_bf._base;
fp->_r = fp->_read (ptr, fp->_cookie, (char *) fp->_p, fp->_bf._size);
#ifndef __CYGWIN__