2004-03-25 Thomas Pfaff <tpfaff@gmx.net>
* libc/stdio/fclose.c (fclose): Protect file pointer list when releasing a file. * libc/stdio/fcloseall.c (_fcloseall_r): Close all files via fwalk. * libc/stdio/fdopen.c (_fdopen_r): Add calls to _flockfile/_funlockfile. * libc/stdio/findfp.c: Move __sfp_lock. Change __sfp_lock type to recursive. Change __lock_acquire/__lock_release calls for __sfp_lock to __sfp_lock_acquire/__sfp_lock_release throughout. (std): Make sure that file lock is only initialized once. (__sfp): Move _file initialization. Initialize file lock. (__sfp_lock_acquire): New function. (__sfp_lock_release): Ditto. (__fp_lock_all): Remove __sfp_lock_acquire call. (__fp_unlock_all): Remove __sfp_lock_release call. * libc/stdio/fopen.c (_fopen_r): Protect file pointer list. Add calls to _flockfile/_funlockfile. Remove __lock_init_recursive call. * libc/stdio/freopen.c (_freopen_r): Protect file pointer list. * libc/stdio/fwalk.c (__fwalk): New static function. (_fwalk): Protect file pointer list. Use __fwalk to walk through file pointers. * libc/stdio/local.h: Add defines for __sfp_lock_acquire/__sfp_lock_release when single threaded. Add function prototypes otherwise. * libc/stdio64/fdopen64.c (_fdopen64_r): Add calls to _flockfile/_funlockfile. * libc/stdio/fopen64.c (_fopen64_r): Protect file pointer list. Add calls to _flockfile/_funlockfile. Remove __lock_init_recursive call. * libc/stdio/freopen64.c (_freopen64_r): Protect file pointer list.
This commit is contained in:
@ -87,14 +87,17 @@ _DEFUN (_freopen_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;
|
||||
}
|
||||
|
||||
@ -148,12 +151,13 @@ _DEFUN (_freopen_r, (ptr, file, mode, fp),
|
||||
|
||||
if (f < 0)
|
||||
{ /* did not get it after all */
|
||||
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
|
||||
fp->_flags = 0; /* set it free */
|
||||
__sfp_lock_release ();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -171,6 +175,7 @@ _DEFUN (_freopen_r, (ptr, file, mode, fp),
|
||||
#endif
|
||||
|
||||
_funlockfile(fp);
|
||||
__sfp_lock_release ();
|
||||
return fp;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user