Index: newlib/libc/stdio/findfp.c |
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c |
index 6e5873ffe3dfdd57e5b1810d74911b65a660bd3e..56c143d209e50ed5a004c4f26f1d8942e17f4dbd 100644 |
--- a/newlib/libc/stdio/findfp.c |
+++ b/newlib/libc/stdio/findfp.c |
@@ -107,6 +107,7 @@ _DEFUN(__sfp, (d), |
FILE *fp; |
int n; |
struct _glue *g; |
+ int found_fp = 0; |
CHECK_INIT(_GLOBAL_REENT, NULL); |
@@ -115,8 +116,13 @@ _DEFUN(__sfp, (d), |
for (g = &_GLOBAL_REENT->__sglue;; g = g->_next) |
{ |
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++) |
- if (fp->_flags == 0) |
- goto found; |
+ { |
+ _flockfile(fp); |
+ found_fp = (fp->_flags == 0); |
+ _funlockfile(fp); |
+ if (found_fp) |
+ goto found; |
+ } |
if (g->_next == NULL && |
(g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL) |
break; |