about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile2
-rw-r--r--libio/fcloseall.c37
-rw-r--r--libio/iofclose.c33
-rw-r--r--libio/stdio.h3
4 files changed, 53 insertions, 22 deletions
diff --git a/libio/Makefile b/libio/Makefile
index 53a1d7d843..00eeb54fee 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -32,7 +32,7 @@ routines	:=							      \
 									      \
 	clearerr feof ferror fgetc fileno fputc freopen fseek getc getchar    \
 	memstream pclose putc putchar rewind setbuf setlinebuf vasprintf      \
-	vdprintf vscanf vsnprintf obprintf				      \
+	vdprintf vscanf vsnprintf obprintf fcloseall			      \
 									      \
 	libc_fatal
 
diff --git a/libio/fcloseall.c b/libio/fcloseall.c
new file mode 100644
index 0000000000..56233b0a5c
--- /dev/null
+++ b/libio/fcloseall.c
@@ -0,0 +1,37 @@
+/*
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
+
+This file is part of the GNU IO Library.  This library is free
+software; you can redistribute it and/or modify it under the
+terms of the GNU General Public License as published by the
+Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this library; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+As a special exception, if you link this library with files
+compiled with a GNU compiler to produce an executable, this does not cause
+the resulting executable to be covered by the GNU General Public License.
+This exception does not however invalidate any other reasons why
+the executable file might be covered by the GNU General Public License. */
+
+#include "libioP.h"
+#ifdef __STDC__
+#include <stdlib.h>
+#endif
+
+int
+__fcloseall ()
+{
+  /* Close all streams.  */
+  _IO_cleanup ();
+  return 0;
+}
+weak_alias (__fcloseall, fcloseall)
diff --git a/libio/iofclose.c b/libio/iofclose.c
index 79a0543471..67fadbed2d 100644
--- a/libio/iofclose.c
+++ b/libio/iofclose.c
@@ -33,29 +33,20 @@ _IO_fclose (fp)
 {
   int status;
 
-  if (fp == NULL)
-    {
-      /* Close all streams.  */
-      _IO_cleanup ();
-      status = 0;
-    }
+  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)
     {
-      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);
-	}
+      fp->_IO_file_flags = 0;
+      free(fp);
     }
 
   return status;
diff --git a/libio/stdio.h b/libio/stdio.h
index ba5fa5438e..e732fa6791 100644
--- a/libio/stdio.h
+++ b/libio/stdio.h
@@ -166,6 +166,9 @@ extern int __vsscanf __P ((__const char *, __const char *, _G_va_list));
 #endif
 
 #ifdef __USE_GNU
+extern int __fcloseall __P ((void));
+extern int fcloseall __P ((void));
+
 struct obstack;
 extern int obstack_vprintf __P ((struct obstack *__obstack,
 				 __const char *__fmt, _G_va_list));