summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-17 18:28:17 +0200
committerBruno Haible <bruno@clisp.org>2011-09-17 18:28:17 +0200
commit25399c1aba359704fab2f4f5164011df43e1795e (patch)
tree91d9dd46a511fd9ab32f57b98f945d839e445a0a
parenteef112c69472818b6aa3673505c24e1f41571b7d (diff)
downloadgnulib-25399c1aba359704fab2f4f5164011df43e1795e.tar.gz
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. * m4/popen.m4 (gl_FUNC_POPEN): Test if popen exists. Set HAVE_POPEN. * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize HAVE_POPEN. * modules/popen (Depends-on, configure.ac): Update condition. * modules/stdio (Makefile.am): Substitute HAVE_POPEN. * doc/posix-functions/popen.texi: Mention that the MSVC problem is fixed.
-rw-r--r--ChangeLog12
-rw-r--r--doc/posix-functions/popen.texi6
-rw-r--r--lib/popen.c31
-rw-r--r--lib/stdio.in.h4
-rw-r--r--m4/popen.m451
-rw-r--r--m4/stdio_h.m43
-rw-r--r--modules/popen4
-rw-r--r--modules/stdio1
8 files changed, 80 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 62d4027cd1..4410912baf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
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.
+ * m4/popen.m4 (gl_FUNC_POPEN): Test if popen exists. Set HAVE_POPEN.
+ * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Initialize HAVE_POPEN.
+ * modules/popen (Depends-on, configure.ac): Update condition.
+ * modules/stdio (Makefile.am): Substitute HAVE_POPEN.
+ * doc/posix-functions/popen.texi: Mention that the MSVC problem is
+ fixed.
+
+2011-09-17 Bruno Haible <bruno@clisp.org>
+
isnanl, isnand, isnanf: Work around MSVC bug.
* lib/isnan.c (FUNC): Use alternate ways of computing NaN and Infinity.
diff --git a/doc/posix-functions/popen.texi b/doc/posix-functions/popen.texi
index 8629c58755..e9fac3be8e 100644
--- a/doc/posix-functions/popen.texi
+++ b/doc/posix-functions/popen.texi
@@ -9,6 +9,9 @@ Gnulib module: popen
Portability problems fixed by Gnulib:
@itemize
@item
+This function is missing on some platforms:
+MSVC 9.
+@item
Some platforms start the child with closed stdin or stdout if the
standard descriptors were closed in the parent:
Cygwin 1.5.x.
@@ -17,9 +20,6 @@ Cygwin 1.5.x.
Portability problems not fixed by Gnulib:
@itemize
@item
-This function is missing on some platforms:
-MSVC 9.
-@item
Some platforms mistakenly set the close-on-exec bit, then if it is
cleared by the application, the platform then leaks file descriptors
from earlier @code{popen} calls into subsequent @code{popen} children:
diff --git a/lib/popen.c b/lib/popen.c
index 64a4f619e4..4330479960 100644
--- a/lib/popen.c
+++ b/lib/popen.c
@@ -21,12 +21,14 @@
/* Specification. */
#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
+#if HAVE_POPEN
-#undef popen
+# include <errno.h>
+# include <fcntl.h>
+# include <stdlib.h>
+# include <unistd.h>
+
+# undef popen
FILE *
rpl_popen (const char *filename, const char *mode)
@@ -80,3 +82,22 @@ rpl_popen (const char *filename, const char *mode)
errno = saved_errno;
return result;
}
+
+#else
+/* Native Woe32 API. */
+
+# include <string.h>
+
+FILE *
+popen (const char *filename, const char *mode)
+{
+ /* Use binary mode by default. */
+ if (strcmp (mode, "r") == 0)
+ mode = "rb";
+ else if (strcmp (mode, "w") == 0)
+ mode = "wb";
+
+ return _popen (filename, mode);
+}
+
+#endif
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index edf521a8bb..a2808fb575 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -781,6 +781,10 @@ _GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
_GL_ARG_NONNULL ((1, 2)));
_GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
# else
+# if !@HAVE_POPEN@
+_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode)
+ _GL_ARG_NONNULL ((1, 2)));
+# endif
_GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
# endif
_GL_CXXALIASWARN (popen);
diff --git a/m4/popen.m4 b/m4/popen.m4
index c45298145f..c958f1950e 100644
--- a/m4/popen.m4
+++ b/m4/popen.m4
@@ -1,4 +1,4 @@
-# popen.m4 serial 4
+# popen.m4 serial 5
dnl Copyright (C) 2009-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,
@@ -7,26 +7,35 @@ dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_POPEN],
[
AC_REQUIRE([gl_STDIO_H_DEFAULTS])
- AC_CACHE_CHECK([whether popen works with closed stdin],
- [gl_cv_func_popen_works],
- [
- AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
-]], [int result = 0;
- FILE *child;
- fclose (stdin);
- fclose (stdout);
- child = popen ("echo a", "r");
- if (fgetc (child) != 'a')
- result |= 1;
- if (pclose (child) != 0)
- result |= 2;
- return result;
-])], [gl_cv_func_popen_works=yes], [gl_cv_func_popen_works=no],
- dnl For now, only cygwin 1.5 or older is known to be broken.
- [gl_cv_func_popen_works='guessing yes'])
- ])
- if test "$gl_cv_func_popen_works" = no; then
- REPLACE_POPEN=1
+ AC_CHECK_FUNCS_ONCE([popen])
+ if test $ac_cv_func_popen = no; then
+ HAVE_POPEN=0
+ else
+ AC_CACHE_CHECK([whether popen works with closed stdin],
+ [gl_cv_func_popen_works],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>]],
+ [[int result = 0;
+ FILE *child;
+ fclose (stdin);
+ fclose (stdout);
+ child = popen ("echo a", "r");
+ if (fgetc (child) != 'a')
+ result |= 1;
+ if (pclose (child) != 0)
+ result |= 2;
+ return result;
+ ]])],
+ [gl_cv_func_popen_works=yes],
+ [gl_cv_func_popen_works=no],
+ dnl For now, only cygwin 1.5 or older is known to be broken.
+ [gl_cv_func_popen_works='guessing yes'])
+ ])
+ if test "$gl_cv_func_popen_works" = no; then
+ REPLACE_POPEN=1
+ fi
fi
])
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index a8326f3c34..d637e13907 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 37
+# stdio_h.m4 serial 38
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,
@@ -153,6 +153,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_POPEN=1; AC_SUBST([HAVE_POPEN])
HAVE_RENAMEAT=1; AC_SUBST([HAVE_RENAMEAT])
HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF])
HAVE_VDPRINTF=1; AC_SUBST([HAVE_VDPRINTF])
diff --git a/modules/popen b/modules/popen
index 37b3cf6ca8..426589ac87 100644
--- a/modules/popen
+++ b/modules/popen
@@ -7,11 +7,11 @@ m4/popen.m4
Depends-on:
stdio
-open [test $REPLACE_POPEN = 1]
+open [test $HAVE_POPEN = 0 || $REPLACE_POPEN = 1]
configure.ac:
gl_FUNC_POPEN
-if test $REPLACE_POPEN = 1; then
+if test $HAVE_POPEN = 0 || $REPLACE_POPEN = 1; then
AC_LIBOBJ([popen])
gl_PREREQ_POPEN
fi
diff --git a/modules/stdio b/modules/stdio
index 5fae1b95cf..cd21661e71 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -93,6 +93,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_POPEN''@|$(HAVE_POPEN)|g' \
-e 's|@''HAVE_RENAMEAT''@|$(HAVE_RENAMEAT)|g' \
-e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \
-e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \