New module 'pclose'.
authorBruno Haible <bruno@clisp.org>
Sat, 17 Sep 2011 22:58:06 +0000 (00:58 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 17 Sep 2011 22:58:06 +0000 (00:58 +0200)
* lib/stdio.in.h (pclose): New declaration.
* lib/pclose.c: New file.
* m4/pclose.m4: New file.
* m4/stdio_h.m4 (gl_STDIO_H): Test whether pclose is declared.
(gl_STDIO_H_DEFAULTS): Initialize GNULIB_PCLOSE, HAVE_PCLOSE.
* modules/stdio (Makefile.am): Substitute GNULIB_PCLOSE, HAVE_PCLOSE.
* modules/pclose: New file.
* modules/popen-tests (Depends-on): Add pclose.
* modules/popen-safer-tests (Depends-on): Likewise.
* doc/posix-functions/pclose.texi: Mention the new module.

ChangeLog
doc/posix-functions/pclose.texi
lib/pclose.c [new file with mode: 0644]
lib/stdio.in.h
m4/pclose.m4 [new file with mode: 0644]
m4/stdio_h.m4
modules/pclose [new file with mode: 0644]
modules/popen-safer-tests
modules/popen-tests
modules/stdio

index 4410912..354600f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2011-09-17  Bruno Haible  <bruno@clisp.org>
 
+       New module 'pclose'.
+       * lib/stdio.in.h (pclose): New declaration.
+       * lib/pclose.c: New file.
+       * m4/pclose.m4: New file.
+       * m4/stdio_h.m4 (gl_STDIO_H): Test whether pclose is declared.
+       (gl_STDIO_H_DEFAULTS): Initialize GNULIB_PCLOSE, HAVE_PCLOSE.
+       * modules/stdio (Makefile.am): Substitute GNULIB_PCLOSE, HAVE_PCLOSE.
+       * modules/pclose: New file.
+       * modules/popen-tests (Depends-on): Add pclose.
+       * modules/popen-safer-tests (Depends-on): Likewise.
+       * doc/posix-functions/pclose.texi: Mention the new module.
+
+2011-09-17  Bruno Haible  <bruno@clisp.org>
+
        popen: Support for MSVC.
        * lib/stdio.in.h (popen): Declare it if the system lacks this function.
        * lib/popen.c (popen): Provide alternate definition for native Windows.
index 688c191..d792b02 100644 (file)
@@ -4,15 +4,15 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/pclose.html}
 
-Gnulib module: ---
+Gnulib module: pclose
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+MSVC 9.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This function is missing on some platforms:
-MSVC 9.
 @end itemize
diff --git a/lib/pclose.c b/lib/pclose.c
new file mode 100644 (file)
index 0000000..b171c21
--- /dev/null
@@ -0,0 +1,28 @@
+/* Close a stream to a sub-process.
+   Copyright (C) 2011 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>
+
+/* Native Woe32 API.  */
+
+int
+pclose (FILE *stream)
+{
+  return _pclose (stream);
+}
index a2808fb..f5ffd85 100644 (file)
@@ -750,6 +750,20 @@ _GL_CXXALIAS_SYS (obstack_vprintf, int,
 _GL_CXXALIASWARN (obstack_vprintf);
 #endif
 
+#if @GNULIB_PCLOSE@
+# if !@HAVE_PCLOSE@
+_GL_FUNCDECL_SYS (pclose, int, (FILE *stream) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (pclose, int, (FILE *stream));
+_GL_CXXALIASWARN (pclose);
+#elif defined GNULIB_POSIXCHECK
+# undef pclose
+# if HAVE_RAW_DECL_PCLOSE
+_GL_WARN_ON_USE (pclose, "popen is unportable - "
+                 "use gnulib module pclose for more portability");
+# endif
+#endif
+
 #if @GNULIB_PERROR@
 /* Print a message to standard error, describing the value of ERRNO,
    (if STRING is not NULL and not empty) prefixed with STRING and ": ",
diff --git a/m4/pclose.m4 b/m4/pclose.m4
new file mode 100644 (file)
index 0000000..871c3fa
--- /dev/null
@@ -0,0 +1,20 @@
+# pclose.m4 serial 1
+dnl Copyright (C) 2011 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_PCLOSE],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([pclose])
+  if test $ac_cv_func_pclose = no; then
+    HAVE_PCLOSE=0
+  fi
+])
+
+# Prerequisites of lib/pclose.c.
+AC_DEFUN([gl_PREREQ_PCLOSE],
+[
+  :
+])
index d637e13..988e025 100644 (file)
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 38
+# stdio_h.m4 serial 39
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -74,7 +74,7 @@ AC_DEFUN([gl_STDIO_H],
   dnl corresponding gnulib module is not in use, and which is not
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <stdio.h>
-    ]], [dprintf fpurge fseeko ftello getdelim getline popen renameat
+    ]], [dprintf fpurge fseeko ftello getdelim getline pclose popen renameat
     snprintf tmpfile vdprintf vsnprintf])
 ])
 
@@ -115,6 +115,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   GNULIB_GETS=0;                 AC_SUBST([GNULIB_GETS])
   GNULIB_OBSTACK_PRINTF=0;       AC_SUBST([GNULIB_OBSTACK_PRINTF])
   GNULIB_OBSTACK_PRINTF_POSIX=0; AC_SUBST([GNULIB_OBSTACK_PRINTF_POSIX])
+  GNULIB_PCLOSE=0;               AC_SUBST([GNULIB_PCLOSE])
   GNULIB_PERROR=0;               AC_SUBST([GNULIB_PERROR])
   GNULIB_POPEN=0;                AC_SUBST([GNULIB_POPEN])
   GNULIB_PRINTF=0;               AC_SUBST([GNULIB_PRINTF])
@@ -153,6 +154,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_DPRINTF=1;                AC_SUBST([HAVE_DPRINTF])
   HAVE_FSEEKO=1;                 AC_SUBST([HAVE_FSEEKO])
   HAVE_FTELLO=1;                 AC_SUBST([HAVE_FTELLO])
+  HAVE_PCLOSE=1;                 AC_SUBST([HAVE_PCLOSE])
   HAVE_POPEN=1;                  AC_SUBST([HAVE_POPEN])
   HAVE_RENAMEAT=1;               AC_SUBST([HAVE_RENAMEAT])
   HAVE_VASPRINTF=1;              AC_SUBST([HAVE_VASPRINTF])
diff --git a/modules/pclose b/modules/pclose
new file mode 100644 (file)
index 0000000..833186f
--- /dev/null
@@ -0,0 +1,28 @@
+Description:
+pclose() function: close a stream to a shell command.
+
+Files:
+lib/pclose.c
+m4/pclose.m4
+
+Depends-on:
+stdio
+
+configure.ac:
+gl_FUNC_PCLOSE
+if test $HAVE_PCLOSE = 0; then
+  AC_LIBOBJ([pclose])
+  gl_PREREQ_PCLOSE
+fi
+gl_STDIO_MODULE_INDICATOR([pclose])
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index 8b212ae..2fa7b2d 100644 (file)
@@ -6,6 +6,7 @@ tests/macros.h
 
 Depends-on:
 dup2
+pclose
 sys_wait
 
 configure.ac:
index f3465b6..25a0e91 100644 (file)
@@ -6,6 +6,7 @@ tests/macros.h
 
 Depends-on:
 dup2
+pclose
 sys_wait
 
 configure.ac:
index cd21661..26bfc12 100644 (file)
@@ -55,6 +55,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's/@''GNULIB_GETS''@/$(GNULIB_GETS)/g' \
              -e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \
              -e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \
+             -e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \
              -e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \
              -e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \
              -e 's/@''GNULIB_PRINTF''@/$(GNULIB_PRINTF)/g' \
@@ -93,6 +94,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_DPRINTF''@|$(HAVE_DPRINTF)|g' \
              -e 's|@''HAVE_FSEEKO''@|$(HAVE_FSEEKO)|g' \
              -e 's|@''HAVE_FTELLO''@|$(HAVE_FTELLO)|g' \
+             -e 's|@''HAVE_PCLOSE''@|$(HAVE_PCLOSE)|g' \
              -e 's|@''HAVE_POPEN''@|$(HAVE_POPEN)|g' \
              -e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \
              -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \