+2008-10-11 Bruno Haible <bruno@clisp.org>
+
+ New module 'fclose'.
+ * modules/fclose: New file.
+ * lib/stdio.in.h (fclose): New declaration.
+ * lib/fclose.c: New file.
+ * m4/fclose.m4: New file.
+ * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize GNULIB_FCLOSE,
+ REPLACE_FCLOSE.
+ * m4/close.m4 (gl_REPLACE_CLOSE): Invoke gl_REPLACE_FCLOSE.
+ * modules/stdio (Makefile.am): Substitute GNULIB_FCLOSE,
+ REPLACE_FCLOSE.
+ * modules/close (Depends-on): fclose.
+ * doc/posix-functions/fclose.texi: Mention the problem on Windows.
+
2008-10-11 Bruno Haible <bruno@clisp.org>
* lib/winsock.c (_gl_close_fd_maybe_socket): If closesocket fails,
POSIX specification: @url{http://www.opengroup.org/susv3xsh/fclose.html}
-Gnulib module: ---
+Gnulib module: fclose
Portability problems fixed by Gnulib:
@itemize
+@item
+On Windows platforms (excluding Cygwin), @code{socket} and @code{accept}
+followed by @code{fdopen} do not return streams that can be closed by
+@code{fclose}.
@end itemize
Portability problems not fixed by Gnulib:
--- /dev/null
+/* close replacement.
+ Copyright (C) 2008 Free Software Foundation, Inc.
+
+ This program 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 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <unistd.h>
+
+/* Override fclose() to call the overridden close(). */
+
+int
+rpl_fclose (FILE *fp)
+#undef fclose
+{
+ int saved_errno = 0;
+
+ if (fflush (fp))
+ saved_errno = errno;
+
+ if (close (fileno (fp)) < 0 && saved_errno == 0)
+ saved_errno = errno;
+
+ fclose (fp); /* will fail with errno = EBADF */
+
+ if (saved_errno != 0)
+ {
+ errno = saved_errno;
+ return EOF;
+ }
+ return 0;
+}
fflush (f))
#endif
+#if @GNULIB_FCLOSE@
+# if @REPLACE_FCLOSE@
+# define fclose rpl_fclose
+ /* Close STREAM and its underlying file descriptor. */
+extern int fclose (FILE *stream);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef fclose
+# define fclose(f) \
+ (GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
+ "use gnulib module fclose for portable " \
+ "POSIX compliance"), \
+ fclose (f))
+#endif
+
#if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef fputc
# define fputc rpl_fputc
-# close.m4 serial 1
+# close.m4 serial 2
dnl Copyright (C) 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_LIBOBJ([close])
fi
REPLACE_CLOSE=1
+ gl_REPLACE_FCLOSE
])
--- /dev/null
+# fclose.m4 serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FCLOSE],
+[
+])
+
+AC_DEFUN([gl_REPLACE_FCLOSE],
+[
+ AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+ if test $REPLACE_FCLOSE != 1; then
+ AC_LIBOBJ([fclose])
+ fi
+ REPLACE_FCLOSE=1
+])
-# stdio_h.m4 serial 13
+# stdio_h.m4 serial 14
dnl Copyright (C) 2007-2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
GNULIB_FTELL=0; AC_SUBST([GNULIB_FTELL])
GNULIB_FTELLO=0; AC_SUBST([GNULIB_FTELLO])
GNULIB_FFLUSH=0; AC_SUBST([GNULIB_FFLUSH])
+ GNULIB_FCLOSE=0; AC_SUBST([GNULIB_FCLOSE])
GNULIB_FPUTC=0; AC_SUBST([GNULIB_FPUTC])
GNULIB_PUTC=0; AC_SUBST([GNULIB_PUTC])
GNULIB_PUTCHAR=0; AC_SUBST([GNULIB_PUTCHAR])
REPLACE_FTELLO=0; AC_SUBST([REPLACE_FTELLO])
REPLACE_FTELL=0; AC_SUBST([REPLACE_FTELL])
REPLACE_FFLUSH=0; AC_SUBST([REPLACE_FFLUSH])
+ REPLACE_FCLOSE=0; AC_SUBST([REPLACE_FCLOSE])
HAVE_DECL_GETDELIM=1; AC_SUBST([HAVE_DECL_GETDELIM])
HAVE_DECL_GETLINE=1; AC_SUBST([HAVE_DECL_GETLINE])
REPLACE_GETLINE=0; AC_SUBST([REPLACE_GETLINE])
Depends-on:
unistd
+fclose
configure.ac:
gl_FUNC_CLOSE
--- /dev/null
+Description:
+fclose() function: close a stream.
+
+Files:
+lib/fclose.c
+m4/fclose.m4
+
+Depends-on:
+stdio
+close
+
+configure.ac:
+gl_FUNC_FCLOSE
+gl_STDIO_MODULE_INDICATOR([fclose])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Bruno Haible
+
-e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
-e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
-e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
+ -e 's|@''GNULIB_FCLOSE''@|$(GNULIB_FCLOSE)|g' \
-e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
-e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
-e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
-e 's|@''REPLACE_FTELLO''@|$(REPLACE_FTELLO)|g' \
-e 's|@''REPLACE_FTELL''@|$(REPLACE_FTELL)|g' \
-e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
+ -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
-e 's|@''HAVE_DECL_GETDELIM''@|$(HAVE_DECL_GETDELIM)|g' \
-e 's|@''HAVE_DECL_GETLINE''@|$(HAVE_DECL_GETLINE)|g' \
-e 's|@''REPLACE_GETLINE''@|$(REPLACE_GETLINE)|g' \