2004-04-08 Artem B. Bityuckiy <abitytsky@softminecorp.com>

* libc/stdio/fclose.c (_fclose_r): New function.
        * libc/stdio/freopen.c (_freopen_r): Call _fclose_r.
        * libc/stdio/fcloseall.c (_fcloseall_r): Call _fwalk_reent.
        * libc/stdio64/freopen64.c (_freopen64_r): Use _fclose_r.
        * libc/include/stdio.h (_fclose_r): New prototype.
        * libc/stdio/fopen.c: Fix typo in comment.

2004-04-08  Jeff Johnston  <jjohnstn@redhat.com>

        * libc/stdio/fwalk.c (_fwalk_reent): New version of _fwalk
        to handle _r reentrant functions.
This commit is contained in:
Jeff Johnston 2004-04-08 22:26:50 +00:00
parent 4121d8cf68
commit 47dcaf565d
8 changed files with 93 additions and 7 deletions

View File

@ -1,3 +1,17 @@
2004-04-08 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/fclose.c (_fclose_r): New function.
* libc/stdio/freopen.c (_freopen_r): Call _fclose_r.
* libc/stdio/fcloseall.c (_fcloseall_r): Call _fwalk_reent.
* libc/stdio64/freopen64.c (_freopen64_r): Use _fclose_r.
* libc/include/stdio.h (_fclose_r): New prototype.
* libc/stdio/fopen.c: Fix typo in comment.
2004-04-08 Jeff Johnston <jjohnstn@redhat.com>
* libc/stdio/fwalk.c (_fwalk_reent): New version of _fwalk
to handle _r reentrant functions.
2004-04-08 Eric Christopher <echristo@redhat.com>
* libc/include/machine/setjmp.h: Fix endif locations.

View File

@ -275,6 +275,7 @@ int _EXFUN(_asprintf_r, (struct _reent *, char **, const char *, ...));
int _EXFUN(_fcloseall_r, (struct _reent *));
FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
int _EXFUN(_fclose_r, (struct _reent *, FILE *));
int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...));
int _EXFUN(_getchar_r, (struct _reent *));
char * _EXFUN(_gets_r, (struct _reent *, char *));

View File

@ -4,21 +4,31 @@ FUNCTION
INDEX
fclose
INDEX
_fclose_r
ANSI_SYNOPSIS
#include <stdio.h>
int fclose(FILE *<[fp]>);
int _fclose_r(void *<[reent]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
int fclose(<[fp]>)
FILE *<[fp]>;
int fclose(<[fp]>)
void *<[reent]>
FILE *<[fp]>;
DESCRIPTION
If the file or stream identified by <[fp]> is open, <<fclose>> closes
it, after first ensuring that any pending data is written (by calling
<<fflush(<[fp]>)>>).
The alternate function <<_fclose_r>> is a reentrant version.
The extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<fclose>> returns <<0>> if successful (including when <[fp]> is
<<NULL>> or not an open file); otherwise, it returns <<EOF>>.
@ -47,6 +57,7 @@ Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
@ -57,8 +68,9 @@ Required OS subroutines: <<close>>, <<fstat>>, <<isatty>>, <<lseek>>,
*/
int
_DEFUN (fclose, (fp),
register FILE * fp)
_DEFUN (_fclose_r, (rptr, fp),
struct _reent *rptr _AND
register FILE * fp)
{
int r;
@ -81,7 +93,7 @@ _DEFUN (fclose, (fp),
if (fp->_close != NULL && (*fp->_close) (fp->_cookie) < 0)
r = EOF;
if (fp->_flags & __SMBF)
_free_r (_REENT, (char *) fp->_bf._base);
_free_r (rptr, (char *) fp->_bf._base);
if (HASUB (fp))
FREEUB (fp);
if (HASLB (fp))
@ -96,3 +108,15 @@ _DEFUN (fclose, (fp),
return (r);
}
#ifndef _REENT_ONLY
int
_DEFUN (fclose, (fp),
register FILE * fp)
{
return _fclose_r(_REENT, fp);
}
#endif

View File

@ -66,7 +66,7 @@ int
_fcloseall_r (ptr)
struct _reent *ptr;
{
return _fwalk (ptr, fclose);
return _fwalk_reent (ptr, _fclose_r);
}
#ifndef _REENT_ONLY

View File

@ -38,7 +38,7 @@ TRAD_SYNOPSIS
char *<[mode]>;
FILE *_fopen_r(<[reent]>, <[file]>, <[mode]>)
char *<[reent]>;
void *<[reent]>;
char *<[file]>;
char *<[mode]>;

View File

@ -96,7 +96,7 @@ _DEFUN (_freopen_r, (ptr, file, mode, fp),
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile(fp);
(void) fclose (fp);
(void) _fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}

View File

@ -48,6 +48,30 @@ __fwalk (ptr, function)
return ret;
}
/* Special version of __fwalk where the function pointer is a reentrant
I/O function (e.g. _fclose_r). */
static int
__fwalk_reent (ptr, reent_function)
struct _reent *ptr;
register int (*reent_function) ();
{
register FILE *fp;
register int n, ret = 0;
register struct _glue *g;
for (g = &ptr->__sglue; g != NULL; g = g->_next)
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags != 0)
{
_flockfile (fp);
if (fp->_flags != 0 && fp->_file != -1)
ret |= (*reent_function) (ptr, fp);
_funlockfile (fp);
}
return ret;
}
int
_fwalk (ptr, function)
struct _reent *ptr;
@ -68,3 +92,26 @@ _fwalk (ptr, function)
return ret;
}
/* Special version of _fwalk which handles a function pointer to a
reentrant I/O function (e.g. _fclose_r). */
int
_fwalk_reent (ptr, reent_function)
struct _reent *ptr;
register int (*reent_function) ();
{
register int ret = 0;
__sfp_lock_acquire ();
/* Must traverse given list for std streams. */
if (ptr != _GLOBAL_REENT)
ret |= __fwalk_reent (ptr, reent_function);
/* Must traverse global list for all other streams. */
ret |= __fwalk_reent (_GLOBAL_REENT, reent_function);
__sfp_lock_release ();
return ret;
}

View File

@ -98,7 +98,7 @@ _DEFUN (_freopen64_r, (ptr, file, mode, fp),
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile(fp);
(void) fclose (fp);
(void) _fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}