Mercurial > hg > octave-kai > gnulib-hg
changeset 15642:5f0f5820c414
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 17 Sep 2011 18:28:17 +0200 |
parents | a23d9939d7a5 |
children | fe99cfdb102f |
files | ChangeLog doc/posix-functions/popen.texi lib/popen.c lib/stdio.in.h m4/popen.m4 m4/stdio_h.m4 modules/popen modules/stdio |
diffstat | 8 files changed, 80 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +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.
--- a/doc/posix-functions/popen.texi +++ b/doc/posix-functions/popen.texi @@ -9,6 +9,9 @@ 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 @@ 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:
--- 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 @@ 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
--- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -781,6 +781,10 @@ _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);
--- 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 @@ 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 ])
--- 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 @@ 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])
--- a/modules/popen +++ b/modules/popen @@ -7,11 +7,11 @@ 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
--- a/modules/stdio +++ b/modules/stdio @@ -93,6 +93,7 @@ -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' \