diff options
Diffstat (limited to 'newlib/libc/stdio64')
-rw-r--r-- | newlib/libc/stdio64/fdopen64.c | 8 | ||||
-rw-r--r-- | newlib/libc/stdio64/fopen64.c | 12 | ||||
-rw-r--r-- | newlib/libc/stdio64/freopen64.c | 11 |
3 files changed, 22 insertions, 9 deletions
diff --git a/newlib/libc/stdio64/fdopen64.c b/newlib/libc/stdio64/fdopen64.c index d0fd0d584..aa5a9ce56 100644 --- a/newlib/libc/stdio64/fdopen64.c +++ b/newlib/libc/stdio64/fdopen64.c @@ -63,6 +63,9 @@ _DEFUN (_fdopen64_r, (ptr, fd, mode), if ((fp = __sfp (ptr)) == 0) return 0; + + _flockfile(fp); + fp->_flags = flags; /* * If opened for appending, but underlying descriptor @@ -99,12 +102,9 @@ _DEFUN (_fdopen64_r, (ptr, fd, mode), fp->_flags |= __SCLE; #endif -#ifndef __SINGLE_THREAD__ - __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); -#endif - fp->_flags |= __SL64; + _funlockfile(fp); return fp; } diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c index 3c69820ee..1feffd1db 100644 --- a/newlib/libc/stdio64/fopen64.c +++ b/newlib/libc/stdio64/fopen64.c @@ -91,10 +91,17 @@ _DEFUN (_fopen64_r, (ptr, file, mode), if ((f = _open64_r (ptr, file, oflags, 0666)) < 0) { + __sfp_lock_acquire (); fp->_flags = 0; /* release */ +#ifndef __SINGLE_THREAD__ + __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); +#endif + __sfp_lock_release (); return NULL; } + _flockfile(fp); + fp->_file = f; fp->_flags = flags; fp->_cookie = (_PTR) fp; @@ -114,10 +121,7 @@ _DEFUN (_fopen64_r, (ptr, file, mode), fp->_flags |= __SL64; -#ifndef __SINGLE_THREAD__ - __lock_init_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); -#endif - + _funlockfile(fp); return fp; } diff --git a/newlib/libc/stdio64/freopen64.c b/newlib/libc/stdio64/freopen64.c index 6e4586cd9..c28cbeee2 100644 --- a/newlib/libc/stdio64/freopen64.c +++ b/newlib/libc/stdio64/freopen64.c @@ -70,6 +70,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #include <stdio.h> #include <fcntl.h> #include <stdlib.h> +#include <sys/lock.h> #include "local64.h" /* @@ -88,14 +89,17 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp), register int f; int flags, oflags, e; + __sfp_lock_acquire (); + _flockfile(fp); CHECK_INIT (fp); if ((flags = __sflags (ptr, mode, &oflags)) == 0) { - (void) fclose (fp); _funlockfile(fp); + (void) fclose (fp); + __sfp_lock_release (); return NULL; } @@ -152,6 +156,10 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp), fp->_flags = 0; /* set it free */ ptr->_errno = e; /* restore in case _close clobbered */ _funlockfile(fp); +#ifndef __SINGLE_THREAD__ + __lock_close_recursive (*(_LOCK_RECURSIVE_T *)&fp->_lock); +#endif + __sfp_lock_release (); return NULL; } @@ -172,6 +180,7 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp), fp->_flags |= __SL64; _funlockfile(fp); + __sfp_lock_release (); return fp; } |