* 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 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.
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 *));
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>>.
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+#include <reent.h>
#include <stdio.h>
#include <stdlib.h>
#include "local.h"
*/
int
-_DEFUN (fclose, (fp),
- register FILE * fp)
+_DEFUN (_fclose_r, (rptr, fp),
+ struct _reent *rptr _AND
+ register FILE * fp)
{
int r;
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))
return (r);
}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN (fclose, (fp),
+ register FILE * fp)
+{
+ return _fclose_r(_REENT, fp);
+}
+
+#endif
+
_fcloseall_r (ptr)
struct _reent *ptr;
{
- return _fwalk (ptr, fclose);
+ return _fwalk_reent (ptr, _fclose_r);
}
#ifndef _REENT_ONLY
char *<[mode]>;
FILE *_fopen_r(<[reent]>, <[file]>, <[mode]>)
- char *<[reent]>;
+ void *<[reent]>;
char *<[file]>;
char *<[mode]>;
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile(fp);
- (void) fclose (fp);
+ (void) _fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}
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;
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;
+}
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile(fp);
- (void) fclose (fp);
+ (void) _fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}