diff options
Diffstat (limited to 'lib/close.c')
-rw-r--r-- | lib/close.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/lib/close.c b/lib/close.c index 378c4f145..e8a1ed5cb 100644 --- a/lib/close.c +++ b/lib/close.c @@ -19,18 +19,45 @@ /* 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 |