From: Bruno Haible Date: Sat, 24 Sep 2011 16:08:50 +0000 (+0200) Subject: fdopen: Support for MSVC 9. X-Git-Tag: v0.1~1750 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=09001dfb3ec39d237f8e248ff347cf1be3e6f0c1;p=gnulib.git fdopen: Support for MSVC 9. * m4/fdopen.m4 (gl_FUNC_FDOPEN): Set REPLACE_FDOPEN also if HAVE_MSVC_INVALID_PARAMETER_HANDLER is 1. * lib/fdopen.c: Include msvc-inval.h. (fdopen_nothrow): New function. (rpl_fdopen): Use it. * modules/fdopen (Depends-on): Add msvc-inval. * modules/fclose-tests (Depends-on): Add fdopen. * modules/fflush-tests (Depends-on): Likewise. * modules/fgetc-tests (Depends-on): Likewise. * modules/fputc-tests (Depends-on): Likewise. * modules/fread-tests (Depends-on): Likewise. * modules/freopen-tests (Depends-on): Likewise. * modules/fseeko-tests (Depends-on): Likewise. * modules/ftello-tests (Depends-on): Likewise. * modules/fwrite-tests (Depends-on): Likewise. * doc/posix-functions/fdopen.texi: Mention the problem on MSVC. --- diff --git a/ChangeLog b/ChangeLog index ceca56261..9def2635e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,25 @@ 2011-09-24 Bruno Haible + fdopen: Support for MSVC 9. + * m4/fdopen.m4 (gl_FUNC_FDOPEN): Set REPLACE_FDOPEN also if + HAVE_MSVC_INVALID_PARAMETER_HANDLER is 1. + * lib/fdopen.c: Include msvc-inval.h. + (fdopen_nothrow): New function. + (rpl_fdopen): Use it. + * modules/fdopen (Depends-on): Add msvc-inval. + * modules/fclose-tests (Depends-on): Add fdopen. + * modules/fflush-tests (Depends-on): Likewise. + * modules/fgetc-tests (Depends-on): Likewise. + * modules/fputc-tests (Depends-on): Likewise. + * modules/fread-tests (Depends-on): Likewise. + * modules/freopen-tests (Depends-on): Likewise. + * modules/fseeko-tests (Depends-on): Likewise. + * modules/ftello-tests (Depends-on): Likewise. + * modules/fwrite-tests (Depends-on): Likewise. + * doc/posix-functions/fdopen.texi: Mention the problem on MSVC. + +2011-09-24 Bruno Haible + fgetc, fputc, fread, fwrite tests: Avoid compilation error on MSVC. * modules/fgetc-tests (Depends-on): Add unistd. * modules/fputc-tests (Depends-on): Likewise. diff --git a/doc/posix-functions/fdopen.texi b/doc/posix-functions/fdopen.texi index 49c006719..58e582f87 100644 --- a/doc/posix-functions/fdopen.texi +++ b/doc/posix-functions/fdopen.texi @@ -9,6 +9,9 @@ Gnulib module: fdopen Portability problems fixed by Gnulib: @itemize @item +This function crashes when invoked with invalid arguments on some platforms: +MSVC 9. +@item On Windows platforms (excluding Cygwin), this function does not set @code{errno} upon failure. @end itemize diff --git a/lib/fdopen.c b/lib/fdopen.c index c443ab660..50c889b17 100644 --- a/lib/fdopen.c +++ b/lib/fdopen.c @@ -21,8 +21,34 @@ #include +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif + #undef fdopen +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static FILE * +fdopen_nothrow (int fd, const char *mode) +{ + FILE *result; + + TRY_MSVC_INVAL + { + result = fdopen (fd, mode); + } + CATCH_MSVC_INVAL + { + result = NULL; + } + DONE_MSVC_INVAL; + + return result; +} +#else +# define fdopen_nothrow fdopen +#endif + FILE * rpl_fdopen (int fd, const char *mode) { @@ -30,7 +56,7 @@ rpl_fdopen (int fd, const char *mode) FILE *fp; errno = 0; - fp = fdopen (fd, mode); + fp = fdopen_nothrow (fd, mode); if (fp == NULL) { if (errno == 0) diff --git a/m4/fdopen.m4 b/m4/fdopen.m4 index dd2cf264d..8cae2fc27 100644 --- a/m4/fdopen.m4 +++ b/m4/fdopen.m4 @@ -1,4 +1,4 @@ -# fdopen.m4 serial 1 +# fdopen.m4 serial 2 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, @@ -8,12 +8,15 @@ AC_DEFUN([gl_FUNC_FDOPEN], [ AC_REQUIRE([gl_STDIO_H_DEFAULTS]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - - dnl Test whether fdopen() sets errno when it fails due to a bad fd argument. - AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works], - [ - AC_RUN_IFELSE( - [AC_LANG_SOURCE([[ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_FDOPEN=1 + else + dnl Test whether fdopen() sets errno when it fails due to a bad fd argument. + AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ #include #include int @@ -28,17 +31,18 @@ main (void) return 2; return 0; }]])], - [gl_cv_func_fdopen_works=yes], - [gl_cv_func_fdopen_works=no], - [case "$host_os" in - mingw*) gl_cv_func_fdopen_works="guessing no" ;; - *) gl_cv_func_fdopen_works="guessing yes" ;; - esac - ]) - ]) - case "$gl_cv_func_fdopen_works" in - *no) REPLACE_FDOPEN=1 ;; - esac + [gl_cv_func_fdopen_works=yes], + [gl_cv_func_fdopen_works=no], + [case "$host_os" in + mingw*) gl_cv_func_fdopen_works="guessing no" ;; + *) gl_cv_func_fdopen_works="guessing yes" ;; + esac + ]) + ]) + case "$gl_cv_func_fdopen_works" in + *no) REPLACE_FDOPEN=1 ;; + esac + fi ]) dnl Prerequisites of lib/fdopen.c. diff --git a/modules/fclose-tests b/modules/fclose-tests index 6334f6594..0f36e0d50 100644 --- a/modules/fclose-tests +++ b/modules/fclose-tests @@ -2,6 +2,7 @@ Files: tests/test-fclose.c Depends-on: +fdopen configure.ac: diff --git a/modules/fdopen b/modules/fdopen index 4054b054d..45f47fdbe 100644 --- a/modules/fdopen +++ b/modules/fdopen @@ -7,6 +7,7 @@ m4/fdopen.m4 Depends-on: stdio +msvc-inval [test $REPLACE_FDOPEN = 1] configure.ac: gl_FUNC_FDOPEN diff --git a/modules/fflush-tests b/modules/fflush-tests index a447521f1..33c47c42e 100644 --- a/modules/fflush-tests +++ b/modules/fflush-tests @@ -7,6 +7,7 @@ tests/macros.h Depends-on: binary-io +fdopen fseeko configure.ac: diff --git a/modules/fgetc-tests b/modules/fgetc-tests index 25077f7ad..d812a6f73 100644 --- a/modules/fgetc-tests +++ b/modules/fgetc-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: unistd +fdopen configure.ac: diff --git a/modules/fputc-tests b/modules/fputc-tests index a6c89583e..8f6c2da89 100644 --- a/modules/fputc-tests +++ b/modules/fputc-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: unistd +fdopen configure.ac: diff --git a/modules/fread-tests b/modules/fread-tests index c37901f8d..bb521a46d 100644 --- a/modules/fread-tests +++ b/modules/fread-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: unistd +fdopen configure.ac: diff --git a/modules/freopen-tests b/modules/freopen-tests index 95b59152e..55e9d71c7 100644 --- a/modules/freopen-tests +++ b/modules/freopen-tests @@ -4,6 +4,7 @@ tests/signature.h tests/macros.h Depends-on: +fdopen configure.ac: diff --git a/modules/fseeko-tests b/modules/fseeko-tests index 470a4e4e0..22e1e2b47 100644 --- a/modules/fseeko-tests +++ b/modules/fseeko-tests @@ -11,6 +11,7 @@ tests/macros.h m4/ungetc.m4 Depends-on: +fdopen configure.ac: gl_FUNC_UNGETC_WORKS diff --git a/modules/ftello-tests b/modules/ftello-tests index 3c216d85a..90d269eae 100644 --- a/modules/ftello-tests +++ b/modules/ftello-tests @@ -11,6 +11,7 @@ m4/ungetc.m4 Depends-on: binary-io +fdopen configure.ac: gl_FUNC_UNGETC_WORKS diff --git a/modules/fwrite-tests b/modules/fwrite-tests index 00d8e7e87..56d507498 100644 --- a/modules/fwrite-tests +++ b/modules/fwrite-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: unistd +fdopen configure.ac: