]> Savannah Git Hosting - gnulib.git/commitdiff
close: Support for MSVC 9.
authorBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2011 00:48:19 +0000 (02:48 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 24 Sep 2011 00:48:19 +0000 (02:48 +0200)
* lib/close.c: Include <errno.h>, msvc-inval.h.
(close_nothrow): New function.
(rpl_close): Use it.
* m4/close.m4 (gl_FUNC_CLOSE): Replace close if the platform has an
invalid parameter handler.
* modules/close (Depends-on): Add msvc-inval.
* modules/dup2-tests (Depends-on): Add close.
* modules/dup3-tests (Depends-on): Likewise.
* modules/fcntl-tests (Depends-on): Likewise.
* modules/spawn-pipe-tests (Depends-on): Likewise.
* modules/unistd-safer-tests (Depends-on): Likewise.
* doc/posix-functions/close.texi: Mention the problem on MSVC.

ChangeLog
doc/posix-functions/close.texi
lib/close.c
m4/close.m4
modules/close
modules/dup2-tests
modules/dup3-tests
modules/fcntl-tests
modules/spawn-pipe-tests
modules/unistd-safer-tests

index a81731ea502e9fb998c56a9de043cd410a19a5f0..cfe80269a1740b0ca446965881330f183daafe58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2011-09-23  Bruno Haible  <bruno@clisp.org>
+
+       close: Support for MSVC 9.
+       * lib/close.c: Include <errno.h>, msvc-inval.h.
+       (close_nothrow): New function.
+       (rpl_close): Use it.
+       * m4/close.m4 (gl_FUNC_CLOSE): Replace close if the platform has an
+       invalid parameter handler.
+       * modules/close (Depends-on): Add msvc-inval.
+       * modules/dup2-tests (Depends-on): Add close.
+       * modules/dup3-tests (Depends-on): Likewise.
+       * modules/fcntl-tests (Depends-on): Likewise.
+       * modules/spawn-pipe-tests (Depends-on): Likewise.
+       * modules/unistd-safer-tests (Depends-on): Likewise.
+       * doc/posix-functions/close.texi: Mention the problem on MSVC.
+
 2011-09-23  Bruno Haible  <bruno@clisp.org>
 
        New module 'dup'.
index e93156f41f6e6da60e3371486e0ab8310951f16b..a1dc7034b456d8e4aa12ae58b26afe26f86b0a60 100644 (file)
@@ -9,6 +9,9 @@ Gnulib module: close
 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), @code{socket} and @code{accept}
 do not return file descriptors that can be closed by @code{close}.
 Instead, @code{closesocket} must be used.
index 2c41c75b8ba84fbd8e32479ec4f0ca4913ea905b..c2197fe0a6c6940440d4ff53d195953580776181 100644 (file)
 /* Specification.  */
 #include <unistd.h>
 
+#include <errno.h>
+
 #include "fd-hook.h"
+#include "msvc-inval.h"
+
+#undef close
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+close_nothrow (int fd)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = close (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define close_nothrow close
+#endif
 
 /* Override close() to call into other gnulib modules.  */
 
 int
 rpl_close (int fd)
-#undef close
 {
 #if WINDOWS_SOCKETS
-  int retval = execute_all_close_hooks (close, fd);
+  int retval = execute_all_close_hooks (close_nothrow, fd);
 #else
-  int retval = close (fd);
+  int retval = close_nothrow (fd);
 #endif
 
 #if REPLACE_FCHDIR
index cd30d08cf61ead0d612f1fafa610d5c3c71338be..f860a320c16733021b1dbbc99c86ff49ad12fb8c 100644 (file)
@@ -1,4 +1,4 @@
-# close.m4 serial 7
+# close.m4 serial 8
 dnl Copyright (C) 2008-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,6 +7,10 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_CLOSE],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_CLOSE=1
+  fi
   m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
     gl_PREREQ_SYS_H_WINSOCK2
     if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
index adec0401e36f3d0a89a9e14cc5b02d2135b4cc4b..6451ce2f7effdccae1060a5d9f29e3f1d80c8aaf 100644 (file)
@@ -8,6 +8,7 @@ m4/close.m4
 Depends-on:
 unistd
 fd-hook         [test $REPLACE_CLOSE = 1]
+msvc-inval      [test $REPLACE_CLOSE = 1]
 
 configure.ac:
 gl_FUNC_CLOSE
index 8277e3b170c47bbbe9961a41ed12d75244328c60..25a4a18b3cb3b32c6562affd921857c3dec28f06 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 binary-io
+close
 msvc-nothrow
 open
 
index 02f422e845f206e0f029a300289622e6b19f67a0..03f1cad5e4e8536fde0d977023fc1403e7c79f12 100644 (file)
@@ -6,6 +6,7 @@ tests/macros.h
 Depends-on:
 msvc-nothrow
 open
+close
 
 configure.ac:
 
index 72705801e536a3d9b1c6c8bbbbe4efa51396b341..5e34440e7b7da8d2d6c18954a2a8d38f1a5b4eae 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 
 Depends-on:
 binary-io
+close
 getdtablesize
 msvc-nothrow
 stdbool
index 16d96fcd9a137eefa95b44d06b2b8c46ab0e5840..f7831d5e4d4636d9e1563ff8564eb5b735611e86 100644 (file)
@@ -5,6 +5,7 @@ tests/test-spawn-pipe-child.c
 tests/macros.h
 
 Depends-on:
+close
 
 configure.ac:
 
index 03e753c456f42452ce7df9bea9aed2b8408a7b2a..cd2bbcd34af24cb36d3f7eced8070c4c0fc4143e 100644 (file)
@@ -5,6 +5,7 @@ tests/macros.h
 Depends-on:
 binary-io
 cloexec
+close
 dup
 fd-safer-flag
 msvc-nothrow