summaryrefslogtreecommitdiffstats
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.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index 235ffba53..fb1f6c4db 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -95,7 +95,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
register FILE *__restrict fp)
{
register int f;
- int flags, oflags;
+ int flags, oflags, oflags2;
int e = 0;
CHECK_INIT (ptr, fp);
@@ -106,11 +106,14 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
int __oldcancel;
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldcancel);
#endif
- _flockfile (fp);
+ oflags2 = fp->_flags2;
+ if (!(oflags2 & __SNLK))
+ _flockfile (fp);
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
- _funlockfile (fp);
+ if (!(oflags2 & __SNLK))
+ _funlockfile (fp);
#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif
@@ -217,7 +220,8 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
__sfp_lock_acquire ();
fp->_flags = 0; /* set it free */
ptr->_errno = e; /* restore in case _close clobbered */
- _funlockfile (fp);
+ if (!(oflags2 & __SNLK))
+ _funlockfile (fp);
#ifndef __SINGLE_THREAD__
__lock_close_recursive (fp->_lock);
#endif
@@ -241,7 +245,8 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
fp->_flags |= __SCLE;
#endif
- _funlockfile (fp);
+ if (!(oflags2 & __SNLK))
+ _funlockfile (fp);
#ifdef _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
pthread_setcancelstate (__oldcancel, &__oldcancel);
#endif