about summary refs log tree commit diff
path: root/libio/iofclose.c
diff options
context:
space:
mode:
Diffstat (limited to 'libio/iofclose.c')
-rw-r--r--libio/iofclose.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/libio/iofclose.c b/libio/iofclose.c
index 77c7b50088..79a0543471 100644
--- a/libio/iofclose.c
+++ b/libio/iofclose.c
@@ -33,21 +33,31 @@ _IO_fclose (fp)
 {
   int status;
 
-  CHECK_FILE(fp, EOF);
-
-  __libc_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
-  _IO_flockfile (fp);
-  if (fp->_IO_file_flags & _IO_IS_FILEBUF)
-    status = _IO_file_close_it (fp);
+  if (fp == NULL)
+    {
+      /* Close all streams.  */
+      _IO_cleanup ();
+      status = 0;
+    }
   else
-    status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
-  _IO_FINISH (fp);
-  __libc_cleanup_region_end (1);
-  if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
     {
-      fp->_IO_file_flags = 0;
-      free(fp);
+      CHECK_FILE(fp, EOF);
+
+      _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp);
+      _IO_flockfile (fp);
+      if (fp->_IO_file_flags & _IO_IS_FILEBUF)
+	status = _IO_file_close_it (fp);
+      else
+	status = fp->_flags & _IO_ERR_SEEN ? -1 : 0;
+      _IO_FINISH (fp);
+      _IO_cleanup_region_end (1);
+      if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr)
+	{
+	  fp->_IO_file_flags = 0;
+	  free(fp);
+	}
     }
+
   return status;
 }