changeset 30178:b6228c6edb31

Support SIGPIPE in stdio functions for writing.
author Bruno Haible <bruno@clisp.org>
date Fri, 26 Sep 2008 13:37:33 +0200
parents 276a48d7448f
children 6b12ae9f5cdb
files ChangeLog doc/posix-functions/fprintf.texi doc/posix-functions/fputc.texi doc/posix-functions/fputs.texi doc/posix-functions/fwrite.texi doc/posix-functions/printf.texi doc/posix-functions/putc.texi doc/posix-functions/putchar.texi doc/posix-functions/puts.texi doc/posix-functions/vfprintf.texi doc/posix-functions/vprintf.texi lib/stdio-write.c lib/stdio.in.h m4/fprintf-posix.m4 m4/printf-posix-rpl.m4 m4/stdio_h.m4 m4/vfprintf-posix.m4 m4/vprintf-posix.m4 modules/stdio
diffstat 19 files changed, 369 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 26 13:33:00 2008 +0200
+++ b/ChangeLog	Fri Sep 26 13:37:33 2008 +0200
@@ -23,6 +23,43 @@
 
 2008-09-26  Bruno Haible  <bruno@clisp.org>
 
+	* lib/stdio.in.h (fprintf, vfprintf, printf, vprintf, fputc, putc,
+	putchar, fputs, puts, fwrite): Replace when REPLACE_STDIO_WRITE_FUNCS
+	and GNULIB_STDIO_H_SIGPIPE are set.
+	* lib/stdio-write.c: New file.
+	* m4/stdio_h.m4 (gl_STDIO_H): Set GNULIB_FPRINTF, GNULIB_PRINTF,
+	GNULIB_VFPRINTF, GNULIB_VPRINTF, GNULIB_FPUTC, GNULIB_PUTC,
+	GNULIB_PUTCHAR, GNULIB_FPUTS, GNULIB_PUTS, GNULIB_FWRITE,
+	REPLACE_STDIO_WRITE_FUNCS.
+	(gl_STDIO_H_DEFAULTS): Initialize GNULIB_FPRINTF, GNULIB_PRINTF,
+	GNULIB_VFPRINTF, GNULIB_VPRINTF, GNULIB_FPUTC, GNULIB_PUTC,
+	GNULIB_PUTCHAR, GNULIB_FPUTS, GNULIB_PUTS, GNULIB_FWRITE,
+	GNULIB_STDIO_H_SIGPIPE, REPLACE_STDIO_WRITE_FUNCS.
+	* modules/stdio (Files): Add lib/stdio-write.c.
+	(Makefile.am): Substitute GNULIB_FPRINTF, GNULIB_PRINTF,
+	GNULIB_VFPRINTF, GNULIB_VPRINTF, GNULIB_FPUTC, GNULIB_PUTC,
+	GNULIB_PUTCHAR, GNULIB_FPUTS, GNULIB_PUTS, GNULIB_FWRITE,
+	GNULIB_STDIO_H_SIGPIPE, REPLACE_STDIO_WRITE_FUNCS.
+	* m4/fprintf-posix.m4 (gl_REPLACE_FPRINTF): Define
+	REPLACE_FPRINTF_POSIX.
+	* m4/printf-posix-rpl.m4 (gl_REPLACE_PRINTF): Define
+	REPLACE_PRINTF_POSIX.
+	* m4/vfprintf-posix.m4 (gl_REPLACE_VFPRINTF): Define
+	REPLACE_VFPRINTF_POSIX.
+	* m4/vprintf-posix.m4 (gl_REPLACE_VPRINTF): Define
+	REPLACE_VPRINTF_POSIX.
+	* doc/posix-functions/fprintf.texi: Mention the sigpipe module and the
+	SIGPIPE issue.
+	* doc/posix-functions/fputc.texi: Likewise.
+	* doc/posix-functions/fputs.texi: Likewise.
+	* doc/posix-functions/fwrite.texi: Likewise.
+	* doc/posix-functions/printf.texi: Likewise.
+	* doc/posix-functions/putc.texi: Likewise.
+	* doc/posix-functions/putchar.texi: Likewise.
+	* doc/posix-functions/puts.texi: Likewise.
+	* doc/posix-functions/vfprintf.texi: Likewise.
+	* doc/posix-functions/vprintf.texi: Likewise.
+
 	* modules/safe-write (Depends-on): Add write.
 
 	* modules/sigpipe-tests: New file.
--- a/doc/posix-functions/fprintf.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/fprintf.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,9 +4,9 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fprintf.html}
 
-Gnulib module: fprintf-posix
+Gnulib module: fprintf-posix or stdio, sigpipe
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{fprintf-posix}:
 @itemize
 @item
 This function does not support size specifiers as in C99 (@code{hh}, @code{ll},
@@ -50,6 +50,14 @@
 MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{stdio} or @code{fprintf-posix}, together with module @code{sigpipe}:
+@itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- a/doc/posix-functions/fputc.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/fputc.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fputc.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/fputs.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/fputs.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fputs.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/fwrite.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/fwrite.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/fwrite.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/printf.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/printf.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,9 +4,9 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/printf.html}
 
-Gnulib module: printf-posix
+Gnulib module: printf-posix or stdio, sigpipe
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{printf-posix}:
 @itemize
 @item
 This function does not support size specifiers as in C99 (@code{hh}, @code{ll},
@@ -50,6 +50,14 @@
 MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{stdio} or @code{printf-posix}, together with module @code{sigpipe}:
+@itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- a/doc/posix-functions/putc.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/putc.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/putc.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/putchar.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/putchar.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/putchar.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/puts.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/puts.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,10 +4,14 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/puts.html}
 
-Gnulib module: ---
+Gnulib module: stdio, sigpipe
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/doc/posix-functions/vfprintf.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/vfprintf.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,9 +4,9 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/vfprintf.html}
 
-Gnulib module: vfprintf-posix
+Gnulib module: vfprintf-posix or stdio, sigpipe
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{vfprintf-posix}:
 @itemize
 @item
 This function does not support size specifiers as in C99 (@code{hh}, @code{ll},
@@ -50,6 +50,14 @@
 MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{stdio} or @code{vfprintf-posix}, together with module @code{sigpipe}:
+@itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- a/doc/posix-functions/vprintf.texi	Fri Sep 26 13:33:00 2008 +0200
+++ b/doc/posix-functions/vprintf.texi	Fri Sep 26 13:37:33 2008 +0200
@@ -4,9 +4,9 @@
 
 POSIX specification: @url{http://www.opengroup.org/susv3xsh/vprintf.html}
 
-Gnulib module: vprintf-posix
+Gnulib module: vprintf-posix or stdio, sigpipe
 
-Portability problems fixed by Gnulib:
+Portability problems fixed by Gnulib module @code{vprintf-posix}:
 @itemize
 @item
 This function does not support size specifiers as in C99 (@code{hh}, @code{ll},
@@ -50,6 +50,14 @@
 MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0.
 @end itemize
 
+Portability problems fixed by Gnulib module @code{stdio} or @code{vprintf-posix}, together with module @code{sigpipe}:
+@itemize
+@item
+When writing to a pipe with no readers, this function fails, instead of
+obeying the current @code{SIGPIPE} handler, on some platforms:
+mingw.
+@end itemize
+
 Portability problems not fixed by Gnulib:
 @itemize
 @end itemize
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/stdio-write.c	Fri Sep 26 13:37:33 2008 +0200
@@ -0,0 +1,147 @@
+/* POSIX compatible FILE stream write function.
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Bruno Haible <bruno@clisp.org>, 2008.
+
+   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>
+
+/* Replace these functions only if module 'sigpipe' is requested.  */
+#if GNULIB_SIGPIPE
+
+/* On native Windows platforms, SIGPIPE does not exist.  When write() is
+   called on a pipe with no readers, WriteFile() fails with error
+   GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
+   error EINVAL.  This write() function is at the basis of the function
+   which flushes the buffer of a FILE stream.  */
+
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+#  include <errno.h>
+#  include <signal.h>
+#  include <io.h>
+
+#  define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+#  include <windows.h>
+
+#  define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
+  if (ferror (stream))							      \
+    return (EXPRESSION);						      \
+  else									      \
+    {									      \
+      RETTYPE ret;							      \
+      SetLastError (0);							      \
+      ret = (EXPRESSION);						      \
+      if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream))      \
+	{								      \
+	  int fd = fileno (stream);					      \
+	  if (fd >= 0 && GetFileType (_get_osfhandle (fd)) == FILE_TYPE_PIPE) \
+	    {								      \
+	      /* Try to raise signal SIGPIPE.  */			      \
+	      raise (SIGPIPE);						      \
+	      /* If it is currently blocked or ignored, change errno from     \
+		 EINVAL to EPIPE.  */					      \
+	      errno = EPIPE;						      \
+	    }								      \
+	}								      \
+      return ret;							      \
+    }
+
+#  if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
+int
+printf (const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stdout, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
+int
+fprintf (FILE *stream, const char *format, ...)
+{
+  int retval;
+  va_list args;
+
+  va_start (args, format);
+  retval = vfprintf (stream, format, args);
+  va_end (args);
+
+  return retval;
+}
+#  endif
+
+#  if !REPLACE_VFPRINTF_POSIX /* avoid collision with vprintf.c */
+int
+vprintf (const char *format, va_list args)
+{
+  return vfprintf (stdout, format, args);
+}
+#  endif
+
+#  if !REPLACE_VPRINTF_POSIX /* avoid collision with vfprintf.c */
+int
+vfprintf (FILE *stream, const char *format, va_list args)
+#undef vfprintf
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
+}
+#  endif
+
+int
+putchar (int c)
+{
+  return fputc (c, stdout);
+}
+
+int
+fputc (int c, FILE *stream)
+#undef fputc
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
+}
+
+int
+fputs (const char *string, FILE *stream)
+#undef fputs
+{
+  CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
+}
+
+int
+puts (const char *string)
+#undef puts
+{
+  FILE *stream = stdout;
+  CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
+}
+
+size_t
+fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
+#undef fwrite
+{
+  CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
+}
+
+# endif
+#endif
--- a/lib/stdio.in.h	Fri Sep 26 13:33:00 2008 +0200
+++ b/lib/stdio.in.h	Fri Sep 26 13:37:33 2008 +0200
@@ -73,6 +73,10 @@
 extern int fprintf (FILE *fp, const char *format, ...)
        __attribute__ ((__format__ (__printf__, 2, 3)));
 # endif
+#elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# define fprintf rpl_fprintf
+extern int fprintf (FILE *fp, const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 2, 3)));
 #elif defined GNULIB_POSIXCHECK
 # undef fprintf
 # define fprintf \
@@ -88,6 +92,10 @@
 extern int vfprintf (FILE *fp, const char *format, va_list args)
        __attribute__ ((__format__ (__printf__, 2, 0)));
 # endif
+#elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# define vfprintf rpl_vfprintf
+extern int vfprintf (FILE *fp, const char *format, va_list args)
+       __attribute__ ((__format__ (__printf__, 2, 0)));
 #elif defined GNULIB_POSIXCHECK
 # undef vfprintf
 # define vfprintf(s,f,a) \
@@ -104,6 +112,11 @@
 extern int printf (const char *format, ...)
        __attribute__ ((__format__ (__printf__, 1, 2)));
 # endif
+#elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+/* Don't break __attribute__((format(printf,M,N))).  */
+# define printf __printf__
+extern int printf (const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 1, 2)));
 #elif defined GNULIB_POSIXCHECK
 # undef printf
 # define printf \
@@ -126,6 +139,10 @@
 extern int vprintf (const char *format, va_list args)
        __attribute__ ((__format__ (__printf__, 1, 0)));
 # endif
+#elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# define vprintf rpl_vprintf
+extern int vprintf (const char *format, va_list args)
+       __attribute__ ((__format__ (__printf__, 1, 0)));
 #elif defined GNULIB_POSIXCHECK
 # undef vprintf
 # define vprintf(f,a) \
@@ -354,6 +371,42 @@
     fflush (f))
 #endif
 
+#if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef fputc
+# define fputc rpl_fputc
+extern int fputc (int c, FILE *stream);
+#endif
+
+#if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef putc
+# define putc rpl_fputc
+extern int putc (int c, FILE *stream);
+#endif
+
+#if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef putchar
+# define putchar rpl_putchar
+extern int putchar (int c);
+#endif
+
+#if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef fputs
+# define fputs rpl_fputs
+extern int fputs (const char *string, FILE *stream);
+#endif
+
+#if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef puts
+# define puts rpl_puts
+extern int puts (const char *string);
+#endif
+
+#if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
+# undef fwrite
+# define fwrite rpl_fwrite
+extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
+#endif
+
 #if @GNULIB_GETDELIM@
 # if !@HAVE_DECL_GETDELIM@
 /* Read input, up to (and including) the next occurrence of DELIMITER, from
--- a/m4/fprintf-posix.m4	Fri Sep 26 13:33:00 2008 +0200
+++ b/m4/fprintf-posix.m4	Fri Sep 26 13:37:33 2008 +0200
@@ -1,4 +1,4 @@
-# fprintf-posix.m4 serial 11
+# fprintf-posix.m4 serial 12
 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,
@@ -96,6 +96,8 @@
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_LIBOBJ([fprintf])
   REPLACE_FPRINTF=1
+  AC_DEFINE([REPLACE_FPRINTF_POSIX], 1,
+    [Define if fprintf is overridden by a POSIX compliant gnulib implementation.])
   gl_PREREQ_FPRINTF
 ])
 
--- a/m4/printf-posix-rpl.m4	Fri Sep 26 13:33:00 2008 +0200
+++ b/m4/printf-posix-rpl.m4	Fri Sep 26 13:37:33 2008 +0200
@@ -1,5 +1,5 @@
-# printf-posix-rpl.m4 serial 1
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# printf-posix-rpl.m4 serial 2
+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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -17,6 +17,8 @@
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_LIBOBJ([printf])
   REPLACE_PRINTF=1
+  AC_DEFINE([REPLACE_PRINTF_POSIX], 1,
+    [Define if printf is overridden by a POSIX compliant gnulib implementation.])
   gl_PREREQ_PRINTF
 ])
 
--- a/m4/stdio_h.m4	Fri Sep 26 13:33:00 2008 +0200
+++ b/m4/stdio_h.m4	Fri Sep 26 13:37:33 2008 +0200
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 12
+# stdio_h.m4 serial 13
 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,
@@ -8,6 +8,28 @@
 [
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   gl_CHECK_NEXT_HEADERS([stdio.h])
+  dnl No need to create extra modules for these functions. Everyone who uses
+  dnl <stdio.h> likely needs them.
+  GNULIB_FPRINTF=1
+  GNULIB_PRINTF=1
+  GNULIB_VFPRINTF=1
+  GNULIB_VPRINTF=1
+  GNULIB_FPUTC=1
+  GNULIB_PUTC=1
+  GNULIB_PUTCHAR=1
+  GNULIB_FPUTS=1
+  GNULIB_PUTS=1
+  GNULIB_FWRITE=1
+  dnl This ifdef is just an optimization, to avoid performing a configure
+  dnl check whose result is not used. It does not make the test of
+  dnl GNULIB_STDIO_H_SIGPIPE or GNULIB_SIGPIPE redundant.
+  m4_ifdef([gl_SIGNAL_SIGPIPE], [
+    gl_SIGNAL_SIGPIPE
+    if test $gl_cv_header_signal_h_SIGPIPE != yes; then
+      REPLACE_STDIO_WRITE_FUNCS=1
+      AC_LIBOBJ([stdio-write])
+    fi
+  ])
 ])
 
 AC_DEFUN([gl_STDIO_MODULE_INDICATOR],
@@ -19,11 +41,15 @@
 
 AC_DEFUN([gl_STDIO_H_DEFAULTS],
 [
+  GNULIB_FPRINTF=0;              AC_SUBST([GNULIB_FPRINTF])
   GNULIB_FPRINTF_POSIX=0;        AC_SUBST([GNULIB_FPRINTF_POSIX])
+  GNULIB_PRINTF=0;               AC_SUBST([GNULIB_PRINTF])
   GNULIB_PRINTF_POSIX=0;         AC_SUBST([GNULIB_PRINTF_POSIX])
   GNULIB_SNPRINTF=0;             AC_SUBST([GNULIB_SNPRINTF])
   GNULIB_SPRINTF_POSIX=0;        AC_SUBST([GNULIB_SPRINTF_POSIX])
+  GNULIB_VFPRINTF=0;             AC_SUBST([GNULIB_VFPRINTF])
   GNULIB_VFPRINTF_POSIX=0;       AC_SUBST([GNULIB_VFPRINTF_POSIX])
+  GNULIB_VPRINTF=0;              AC_SUBST([GNULIB_VPRINTF])
   GNULIB_VPRINTF_POSIX=0;        AC_SUBST([GNULIB_VPRINTF_POSIX])
   GNULIB_VSNPRINTF=0;            AC_SUBST([GNULIB_VSNPRINTF])
   GNULIB_VSPRINTF_POSIX=0;       AC_SUBST([GNULIB_VSPRINTF_POSIX])
@@ -37,10 +63,18 @@
   GNULIB_FTELL=0;                AC_SUBST([GNULIB_FTELL])
   GNULIB_FTELLO=0;               AC_SUBST([GNULIB_FTELLO])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
+  GNULIB_FPUTC=0;                AC_SUBST([GNULIB_FPUTC])
+  GNULIB_PUTC=0;                 AC_SUBST([GNULIB_PUTC])
+  GNULIB_PUTCHAR=0;              AC_SUBST([GNULIB_PUTCHAR])
+  GNULIB_FPUTS=0;                AC_SUBST([GNULIB_FPUTS])
+  GNULIB_PUTS=0;                 AC_SUBST([GNULIB_PUTS])
+  GNULIB_FWRITE=0;               AC_SUBST([GNULIB_FWRITE])
   GNULIB_GETDELIM=0;             AC_SUBST([GNULIB_GETDELIM])
   GNULIB_GETLINE=0;              AC_SUBST([GNULIB_GETLINE])
   GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
+  GNULIB_STDIO_H_SIGPIPE=0;      AC_SUBST([GNULIB_STDIO_H_SIGPIPE])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  REPLACE_STDIO_WRITE_FUNCS=0;   AC_SUBST([REPLACE_STDIO_WRITE_FUNCS])
   REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
   REPLACE_VFPRINTF=0;            AC_SUBST([REPLACE_VFPRINTF])
   REPLACE_PRINTF=0;              AC_SUBST([REPLACE_PRINTF])
--- a/m4/vfprintf-posix.m4	Fri Sep 26 13:33:00 2008 +0200
+++ b/m4/vfprintf-posix.m4	Fri Sep 26 13:37:33 2008 +0200
@@ -1,4 +1,4 @@
-# vfprintf-posix.m4 serial 11
+# vfprintf-posix.m4 serial 12
 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,
@@ -96,6 +96,8 @@
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_LIBOBJ([vfprintf])
   REPLACE_VFPRINTF=1
+  AC_DEFINE([REPLACE_VFPRINTF_POSIX], 1,
+    [Define if vfprintf is overridden by a POSIX compliant gnulib implementation.])
   gl_PREREQ_VFPRINTF
 ])
 
--- a/m4/vprintf-posix.m4	Fri Sep 26 13:33:00 2008 +0200
+++ b/m4/vprintf-posix.m4	Fri Sep 26 13:37:33 2008 +0200
@@ -1,5 +1,5 @@
-# vprintf-posix.m4 serial 1
-dnl Copyright (C) 2007 Free Software Foundation, Inc.
+# vprintf-posix.m4 serial 2
+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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -17,6 +17,8 @@
   AC_REQUIRE([gl_STDIO_H_DEFAULTS])
   AC_LIBOBJ([vprintf])
   REPLACE_VPRINTF=1
+  AC_DEFINE([REPLACE_VPRINTF_POSIX], 1,
+    [Define if vprintf is overridden by a POSIX compliant gnulib implementation.])
   gl_PREREQ_VPRINTF
 ])
 
--- a/modules/stdio	Fri Sep 26 13:33:00 2008 +0200
+++ b/modules/stdio	Fri Sep 26 13:37:33 2008 +0200
@@ -3,6 +3,7 @@
 
 Files:
 lib/stdio.in.h
+lib/stdio-write.c
 m4/stdio_h.m4
 
 Depends-on:
@@ -23,11 +24,15 @@
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
+	      -e 's|@''GNULIB_FPRINTF''@|$(GNULIB_FPRINTF)|g' \
 	      -e 's|@''GNULIB_FPRINTF_POSIX''@|$(GNULIB_FPRINTF_POSIX)|g' \
+	      -e 's|@''GNULIB_PRINTF''@|$(GNULIB_PRINTF)|g' \
 	      -e 's|@''GNULIB_PRINTF_POSIX''@|$(GNULIB_PRINTF_POSIX)|g' \
 	      -e 's|@''GNULIB_SNPRINTF''@|$(GNULIB_SNPRINTF)|g' \
 	      -e 's|@''GNULIB_SPRINTF_POSIX''@|$(GNULIB_SPRINTF_POSIX)|g' \
+	      -e 's|@''GNULIB_VFPRINTF''@|$(GNULIB_VFPRINTF)|g' \
 	      -e 's|@''GNULIB_VFPRINTF_POSIX''@|$(GNULIB_VFPRINTF_POSIX)|g' \
+	      -e 's|@''GNULIB_VPRINTF''@|$(GNULIB_VPRINTF)|g' \
 	      -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \
 	      -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \
 	      -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \
@@ -41,9 +46,17 @@
 	      -e 's|@''GNULIB_FTELL''@|$(GNULIB_FTELL)|g' \
 	      -e 's|@''GNULIB_FTELLO''@|$(GNULIB_FTELLO)|g' \
 	      -e 's|@''GNULIB_FFLUSH''@|$(GNULIB_FFLUSH)|g' \
+	      -e 's|@''GNULIB_FPUTC''@|$(GNULIB_FPUTC)|g' \
+	      -e 's|@''GNULIB_PUTC''@|$(GNULIB_PUTC)|g' \
+	      -e 's|@''GNULIB_PUTCHAR''@|$(GNULIB_PUTCHAR)|g' \
+	      -e 's|@''GNULIB_FPUTS''@|$(GNULIB_FPUTS)|g' \
+	      -e 's|@''GNULIB_PUTS''@|$(GNULIB_PUTS)|g' \
+	      -e 's|@''GNULIB_FWRITE''@|$(GNULIB_FWRITE)|g' \
 	      -e 's|@''GNULIB_GETDELIM''@|$(GNULIB_GETDELIM)|g' \
 	      -e 's|@''GNULIB_GETLINE''@|$(GNULIB_GETLINE)|g' \
 	      -e 's|@''GNULIB_PERROR''@|$(GNULIB_PERROR)|g' \
+	      -e 's|@''GNULIB_STDIO_H_SIGPIPE''@|$(GNULIB_STDIO_H_SIGPIPE)|g' \
+	      -e 's|@''REPLACE_STDIO_WRITE_FUNCS''@|$(REPLACE_STDIO_WRITE_FUNCS)|g' \
 	      -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
 	      -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \
 	      -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \