This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

reentrant fclose


Hello.

I've added reentrant version of fclose (_fclose_r). Please, see attached patches and commit if consider necessary.

fclose.c.patch - Add reentrant _fclose_r function. Update documentation.
fcloseall.c.patch, freopen.c.patch, freopen64.c.patch - Use reentrant _fclose_r instead of fclose.
stdio.h.patch - Add _fclose_r prototype.
fopen.c.patch - Fix documentation typo.


--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
--- fclose.c	2004-04-01 11:41:54.000000000 +0400
+++ fclose_new.c	2004-04-01 12:08:54.000000000 +0400
@@ -4,21 +4,31 @@
 
 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 @@
  * 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 @@
  */
 
 int
-_DEFUN (fclose, (fp),
-	register FILE * fp)
+_DEFUN (_fclose_r, (rptr, fp),
+       struct _reent *rptr _AND
+       register FILE * fp)
 {
   int r;
 
@@ -78,7 +90,7 @@
   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))
@@ -91,3 +103,15 @@
 
   return (r);
 }
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN (fclose, (fp),
+	register FILE * fp)
+{
+  return _fclose_r(_REENT, fp);
+}
+
+#endif
+
--- fcloseall.c	2004-03-24 18:54:13.000000000 +0300
+++ fcloseall_new.c	2004-04-01 11:59:44.000000000 +0400
@@ -73,7 +73,7 @@
   for (g = &ptr->__sglue; g != NULL; g = g->_next)
     for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
       if (fp->_flags != 0)
-        ret |= fclose (fp);
+        ret |= _fclose_r (ptr, fp);
   return ret;
 }
 
--- fopen.c	2004-04-01 11:47:24.000000000 +0400
+++ fopen_new.c	2004-04-01 11:48:23.000000000 +0400
@@ -38,7 +38,7 @@
 	char *<[mode]>;
 
 	FILE *_fopen_r(<[reent]>, <[file]>, <[mode]>)
-	char *<[reent]>;
+	void *<[reent]>;
 	char *<[file]>;
 	char *<[mode]>;
 
--- freopen.c	2004-03-24 18:54:13.000000000 +0300
+++ freopen_new.c	2004-04-01 12:33:31.000000000 +0400
@@ -93,7 +93,7 @@
 
   if ((flags = __sflags (ptr, mode, &oflags)) == 0)
     {
-      (void) fclose (fp);
+      (void) _fclose_r (ptr, fp);
       _funlockfile(fp);
       return NULL;
     }
--- freopen64.c	2004-03-24 18:54:13.000000000 +0300
+++ freopen64_new.c	2004-04-01 12:38:55.000000000 +0400
@@ -94,7 +94,7 @@
 
   if ((flags = __sflags (ptr, mode, &oflags)) == 0)
     {
-      (void) fclose (fp);
+      (void) _fclose_r(ptr, fp);
       _funlockfile(fp);
       return NULL;
     }
--- stdio.h	2004-04-01 11:53:13.000000000 +0400
+++ stdio_new.h	2004-04-01 12:13:38.000000000 +0400
@@ -275,6 +275,7 @@
 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]