aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/stdio/freopen.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/freopen.c')
-rw-r--r--newlib/libc/stdio/freopen.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index ec195c8..d5582d4 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -146,14 +146,15 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
else
{
#ifdef HAVE_FCNTL
+ int oldflags;
/*
* Reuse the file descriptor, but only if the access mode is
* unchanged. F_SETFL correctly ignores creation flags.
*/
f = fp->_file;
- if ((oflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
- || ((oflags ^ flags) & O_ACCMODE) != 0
- || _fcntl_r (ptr, f, F_SETFL, flags) == -1)
+ if ((oldflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
+ || ((oldflags ^ oflags) & O_ACCMODE) != 0
+ || _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
f = -1;
#else
/* We cannot modify without fcntl support. */