]> Savannah Git Hosting - gnulib.git/commitdiff
fdopen: Support for MSVC 9.
authorBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2011 16:08:50 +0000 (18:08 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2011 16:08:50 +0000 (18:08 +0200)
* 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.

14 files changed:
ChangeLog
doc/posix-functions/fdopen.texi
lib/fdopen.c
m4/fdopen.m4
modules/fclose-tests
modules/fdopen
modules/fflush-tests
modules/fgetc-tests
modules/fputc-tests
modules/fread-tests
modules/freopen-tests
modules/fseeko-tests
modules/ftello-tests
modules/fwrite-tests

index ceca562617c2798038cffaf2be98ad1162231d7a..9def2635ec9c0f8bc608c09c2785deaa35064e2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2011-09-24  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        fgetc, fputc, fread, fwrite tests: Avoid compilation error on MSVC.
index 49c006719c2f2284aff0d6697536d471035533b1..58e582f873cf81b01ddd4660e18b8583aadb4063 100644 (file)
@@ -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
index c443ab66020095ce2066f0091831eb2f7f96e632..50c889b17a4a9732064e1a3f7587b9fc51fbe0f4 100644 (file)
 
 #include <errno.h>
 
+#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)
index dd2cf264d6c8f67043e16affc7a26fac0e8d581d..8cae2fc2736c831c869e1e4335e703354db00c0f 100644 (file)
@@ -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 <stdio.h>
 #include <errno.h>
 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.
index 6334f6594abadb54d1098ca50c98433dc8161975..0f36e0d50e13a1f971ccb80d6b091e2b4aa8a844 100644 (file)
@@ -2,6 +2,7 @@ Files:
 tests/test-fclose.c
 
 Depends-on:
+fdopen
 
 configure.ac:
 
index 4054b054da8ef8e6fbad6c0b45ebb6162c073bab..45f47fdbe19aa8c7635570fbe0e09a3c408e33b6 100644 (file)
@@ -7,6 +7,7 @@ m4/fdopen.m4
 
 Depends-on:
 stdio
+msvc-inval      [test $REPLACE_FDOPEN = 1]
 
 configure.ac:
 gl_FUNC_FDOPEN
index a447521f1f4815108cd7540e6afcabb5601566f9..33c47c42e8c4f562610e146cce3a389d38f094f1 100644 (file)
@@ -7,6 +7,7 @@ tests/macros.h
 
 Depends-on:
 binary-io
+fdopen
 fseeko
 
 configure.ac:
index 25077f7ad116bc8bda6556f74c57a726fac9a128..d812a6f73d701d78b3781511bca1e9a83ba49c8b 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 unistd
+fdopen
 
 configure.ac:
 
index a6c89583e12cf39fe528debe450e9346f0b374cd..8f6c2da8926eecefff66c137e8c367ffbfe0005a 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 unistd
+fdopen
 
 configure.ac:
 
index c37901f8db4dd5f0dc1ed2becc6bf792740942b4..bb521a46d205b416228f8be7a8adfdfeabb3538c 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 unistd
+fdopen
 
 configure.ac:
 
index 95b59152e55a2e2e6e1e742e667e480bbfa5c41e..55e9d71c7e0e53589c067cd2d00aef75297935bb 100644 (file)
@@ -4,6 +4,7 @@ tests/signature.h
 tests/macros.h
 
 Depends-on:
+fdopen
 
 configure.ac:
 
index 470a4e4e0a45517421d74ef69baeda08474bf07e..22e1e2b4724e487c111b6362d1d80f860c14df4f 100644 (file)
@@ -11,6 +11,7 @@ tests/macros.h
 m4/ungetc.m4
 
 Depends-on:
+fdopen
 
 configure.ac:
 gl_FUNC_UNGETC_WORKS
index 3c216d85a7bdb74349a249cbf5217f88d8546ec3..90d269eae7f1af699130e4610d81d3d46ed4ee0d 100644 (file)
@@ -11,6 +11,7 @@ m4/ungetc.m4
 
 Depends-on:
 binary-io
+fdopen
 
 configure.ac:
 gl_FUNC_UNGETC_WORKS
index 00d8e7e8764ba78528c63acb30af1c64fdc0f0f8..56d507498c2ec330f79b6dedbaa72961d7311f88 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 unistd
+fdopen
 
 configure.ac: