# HG changeset patch # User Bruno Haible # Date 1316825299 -7200 # Node ID 6c4cf50b8b27a5b6d4de7bb7f0e564fb5487d4a7 # Parent 19b1b00228076dbdded2541870add6787b3f279e close: Support for MSVC 9. * lib/close.c: Include , 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-09-23 Bruno Haible + + close: Support for MSVC 9. + * lib/close.c: Include , 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 New module 'dup'. diff --git a/doc/posix-functions/close.texi b/doc/posix-functions/close.texi --- a/doc/posix-functions/close.texi +++ b/doc/posix-functions/close.texi @@ -9,6 +9,9 @@ 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. diff --git a/lib/close.c b/lib/close.c --- a/lib/close.c +++ b/lib/close.c @@ -19,18 +19,45 @@ /* Specification. */ #include +#include + #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 diff --git a/m4/close.m4 b/m4/close.m4 --- a/m4/close.m4 +++ b/m4/close.m4 @@ -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 @@ 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 diff --git a/modules/close b/modules/close --- a/modules/close +++ b/modules/close @@ -8,6 +8,7 @@ Depends-on: unistd fd-hook [test $REPLACE_CLOSE = 1] +msvc-inval [test $REPLACE_CLOSE = 1] configure.ac: gl_FUNC_CLOSE diff --git a/modules/dup2-tests b/modules/dup2-tests --- a/modules/dup2-tests +++ b/modules/dup2-tests @@ -5,6 +5,7 @@ Depends-on: binary-io +close msvc-nothrow open diff --git a/modules/dup3-tests b/modules/dup3-tests --- a/modules/dup3-tests +++ b/modules/dup3-tests @@ -6,6 +6,7 @@ Depends-on: msvc-nothrow open +close configure.ac: diff --git a/modules/fcntl-tests b/modules/fcntl-tests --- a/modules/fcntl-tests +++ b/modules/fcntl-tests @@ -5,6 +5,7 @@ Depends-on: binary-io +close getdtablesize msvc-nothrow stdbool diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests --- a/modules/spawn-pipe-tests +++ b/modules/spawn-pipe-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: +close configure.ac: diff --git a/modules/unistd-safer-tests b/modules/unistd-safer-tests --- a/modules/unistd-safer-tests +++ b/modules/unistd-safer-tests @@ -5,6 +5,7 @@ Depends-on: binary-io cloexec +close dup fd-safer-flag msvc-nothrow