From 9b604b4cbfad7422bacc1c723df1d027b6a7c738 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 23 Sep 2011 21:38:44 +0200 Subject: [PATCH] New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9. * lib/msvc-nothrow.h: New file. * lib/msvc-nothrow.c: New file. * m4/msvc-nothrow.m4: New file. * modules/msvc-nothrow: New file. * lib/dup2.c: Include msvc-nothrow.h. (rpl_dup2): No need to protect _get_osfhandle call here. * lib/accept4.c: Include msvc-nothrow.h. * lib/error.c: Likewise. * lib/fcntl.c: Likewise. * lib/lseek.c: Likewise. * lib/nonblocking.c: Likewise. * lib/poll.c: Likewise. * lib/read.c: Likewise. * lib/select.c: Likewise. * lib/sockets.h: Likewise. * lib/sockets.c: Likewise. * lib/stdio-read.c: Likewise. * lib/stdio-write.c: Likewise. * lib/write.c: Likewise. * lib/w32sock.h: Likewise. * lib/w32spawn.h: Likewise. * lib/flock.c: Include msvc-nothrow.h instead of . * lib/fsync.c: Likewise. * lib/isapipe.c: Likewise. * modules/dup2 (Depends-on): Add msvc-nothrow. * modules/accept4 (Depends-on): Likewise. * modules/error (Depends-on): Likewise. * modules/fcntl (Depends-on): Likewise. * modules/lseek (Depends-on): Likewise. * modules/nonblocking (Depends-on): Likewise. * modules/poll (Depends-on): Likewise. * modules/read (Depends-on): Likewise. * modules/select (Depends-on): Likewise. * modules/sockets (Depends-on): Likewise. * modules/sigpipe (Depends-on): Likewise. * modules/write (Depends-on): Likewise. * modules/accept (Depends-on): Likewise. * modules/bind (Depends-on): Likewise. * modules/connect (Depends-on): Likewise. * modules/gethostname (Depends-on): Likewise. * modules/getpeername (Depends-on): Likewise. * modules/getsockname (Depends-on): Likewise. * modules/getsockopt (Depends-on): Likewise. * modules/ioctl (Depends-on): Likewise. * modules/listen (Depends-on): Likewise. * modules/recv (Depends-on): Likewise. * modules/recvfrom (Depends-on): Likewise. * modules/send (Depends-on): Likewise. * modules/sendto (Depends-on): Likewise. * modules/setsockopt (Depends-on): Likewise. * modules/shutdown (Depends-on): Likewise. * modules/socket (Depends-on): Likewise. * modules/execute (Depends-on): Likewise. * modules/spawn-pipe (Depends-on): Likewise. * modules/flock (Depends-on): Likewise. * modules/fsync (Depends-on): Likewise. * modules/isapipe (Depends-on): Likewise. * tests/test-cloexec.c: Include msvc-nothrow.h. * tests/test-dup-safer.c: Likewise. * tests/test-dup2.c: Likewise. * tests/test-dup3.c: Likewise. * tests/test-fcntl.c: Likewise. * tests/test-pipe.c: Likewise. * tests/test-pipe2.c: Likewise. * modules/cloexec-tests (Depends-on): Add msvc-nothrow. * modules/unistd-safer-tests (Depends-on): Likewise. * modules/dup2-tests (Depends-on): Likewise. * modules/dup3-tests (Depends-on): Likewise. * modules/fcntl-tests (Depends-on): Likewise. * modules/pipe-posix-tests (Depends-on): Likewise. * modules/pipe2-tests (Depends-on): Likewise. --- ChangeLog | 75 ++++++++++++++++++++++++++++++++++++++++++++++ lib/accept4.c | 1 + lib/dup2.c | 16 ++-------- lib/error.c | 2 ++ lib/fcntl.c | 3 ++ lib/flock.c | 6 ++-- lib/fsync.c | 6 ++-- lib/isapipe.c | 6 ++-- lib/lseek.c | 2 ++ lib/msvc-nothrow.c | 50 +++++++++++++++++++++++++++++++ lib/msvc-nothrow.h | 44 +++++++++++++++++++++++++++ lib/nonblocking.c | 2 ++ lib/poll.c | 1 + lib/read.c | 2 ++ lib/select.c | 2 ++ lib/sockets.c | 1 + lib/sockets.h | 2 ++ lib/stdio-read.c | 2 ++ lib/stdio-write.c | 2 ++ lib/w32sock.h | 5 +++- lib/w32spawn.h | 5 +++- lib/write.c | 2 ++ m4/msvc-nothrow.m4 | 10 +++++++ modules/accept | 1 + modules/accept4 | 1 + modules/bind | 1 + modules/cloexec-tests | 1 + modules/connect | 1 + modules/dup2 | 1 + modules/dup2-tests | 1 + modules/dup3-tests | 1 + modules/error | 1 + modules/execute | 1 + modules/fcntl | 1 + modules/fcntl-tests | 1 + modules/flock | 1 + modules/fsync | 1 + modules/gethostname | 1 + modules/getpeername | 1 + modules/getsockname | 1 + modules/getsockopt | 1 + modules/ioctl | 1 + modules/isapipe | 1 + modules/listen | 1 + modules/lseek | 1 + modules/msvc-nothrow | 28 +++++++++++++++++ modules/nonblocking | 1 + modules/pipe-posix-tests | 1 + modules/pipe2-tests | 1 + modules/poll | 1 + modules/read | 1 + modules/recv | 1 + modules/recvfrom | 1 + modules/select | 1 + modules/send | 1 + modules/sendto | 1 + modules/setsockopt | 1 + modules/shutdown | 1 + modules/sigpipe | 1 + modules/socket | 1 + modules/sockets | 1 + modules/spawn-pipe | 1 + modules/unistd-safer-tests | 1 + modules/write | 1 + tests/test-cloexec.c | 2 ++ tests/test-dup-safer.c | 2 ++ tests/test-dup2.c | 2 ++ tests/test-dup3.c | 2 ++ tests/test-fcntl.c | 2 ++ tests/test-pipe.c | 2 ++ tests/test-pipe2.c | 2 ++ 71 files changed, 305 insertions(+), 24 deletions(-) create mode 100644 lib/msvc-nothrow.c create mode 100644 lib/msvc-nothrow.h create mode 100644 m4/msvc-nothrow.m4 create mode 100644 modules/msvc-nothrow diff --git a/ChangeLog b/ChangeLog index 74677b0a3..f6d7f09fb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,80 @@ 2011-09-23 Bruno Haible + New module 'msvc-nothrow'. Makes _get_osfhandle safe on MSVC 9. + * lib/msvc-nothrow.h: New file. + * lib/msvc-nothrow.c: New file. + * m4/msvc-nothrow.m4: New file. + * modules/msvc-nothrow: New file. + * lib/dup2.c: Include msvc-nothrow.h. + (rpl_dup2): No need to protect _get_osfhandle call here. + * lib/accept4.c: Include msvc-nothrow.h. + * lib/error.c: Likewise. + * lib/fcntl.c: Likewise. + * lib/lseek.c: Likewise. + * lib/nonblocking.c: Likewise. + * lib/poll.c: Likewise. + * lib/read.c: Likewise. + * lib/select.c: Likewise. + * lib/sockets.h: Likewise. + * lib/sockets.c: Likewise. + * lib/stdio-read.c: Likewise. + * lib/stdio-write.c: Likewise. + * lib/write.c: Likewise. + * lib/w32sock.h: Likewise. + * lib/w32spawn.h: Likewise. + * lib/flock.c: Include msvc-nothrow.h instead of . + * lib/fsync.c: Likewise. + * lib/isapipe.c: Likewise. + * modules/dup2 (Depends-on): Add msvc-nothrow. + * modules/accept4 (Depends-on): Likewise. + * modules/error (Depends-on): Likewise. + * modules/fcntl (Depends-on): Likewise. + * modules/lseek (Depends-on): Likewise. + * modules/nonblocking (Depends-on): Likewise. + * modules/poll (Depends-on): Likewise. + * modules/read (Depends-on): Likewise. + * modules/select (Depends-on): Likewise. + * modules/sockets (Depends-on): Likewise. + * modules/sigpipe (Depends-on): Likewise. + * modules/write (Depends-on): Likewise. + * modules/accept (Depends-on): Likewise. + * modules/bind (Depends-on): Likewise. + * modules/connect (Depends-on): Likewise. + * modules/gethostname (Depends-on): Likewise. + * modules/getpeername (Depends-on): Likewise. + * modules/getsockname (Depends-on): Likewise. + * modules/getsockopt (Depends-on): Likewise. + * modules/ioctl (Depends-on): Likewise. + * modules/listen (Depends-on): Likewise. + * modules/recv (Depends-on): Likewise. + * modules/recvfrom (Depends-on): Likewise. + * modules/send (Depends-on): Likewise. + * modules/sendto (Depends-on): Likewise. + * modules/setsockopt (Depends-on): Likewise. + * modules/shutdown (Depends-on): Likewise. + * modules/socket (Depends-on): Likewise. + * modules/execute (Depends-on): Likewise. + * modules/spawn-pipe (Depends-on): Likewise. + * modules/flock (Depends-on): Likewise. + * modules/fsync (Depends-on): Likewise. + * modules/isapipe (Depends-on): Likewise. + * tests/test-cloexec.c: Include msvc-nothrow.h. + * tests/test-dup-safer.c: Likewise. + * tests/test-dup2.c: Likewise. + * tests/test-dup3.c: Likewise. + * tests/test-fcntl.c: Likewise. + * tests/test-pipe.c: Likewise. + * tests/test-pipe2.c: Likewise. + * modules/cloexec-tests (Depends-on): Add msvc-nothrow. + * modules/unistd-safer-tests (Depends-on): Likewise. + * modules/dup2-tests (Depends-on): Likewise. + * modules/dup3-tests (Depends-on): Likewise. + * modules/fcntl-tests (Depends-on): Likewise. + * modules/pipe-posix-tests (Depends-on): Likewise. + * modules/pipe2-tests (Depends-on): Likewise. + +2011-09-23 Bruno Haible + dup2: Make code more maintainable. * lib/dup2.c (dup2_nothrow): New function, extracted from rpl_dup2. (rpl_dup2): Use it. diff --git a/lib/accept4.c b/lib/accept4.c index 1e7e7f452..4e1ef1a53 100644 --- a/lib/accept4.c +++ b/lib/accept4.c @@ -23,6 +23,7 @@ #include #include #include "binary-io.h" +#include "msvc-nothrow.h" #ifndef SOCK_CLOEXEC # define SOCK_CLOEXEC 0 diff --git a/lib/dup2.c b/lib/dup2.c index b8798f3f0..e2a44734e 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -29,6 +29,8 @@ /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "msvc-inval.h" @@ -70,19 +72,7 @@ rpl_dup2 (int fd, int desired_fd) future dup2 calls will hang. */ if (fd == desired_fd) { - HANDLE handle; - - TRY_MSVC_INVAL - { - handle = (HANDLE) _get_osfhandle (fd); - } - CATCH_MSVC_INVAL - { - handle = INVALID_HANDLE_VALUE; - } - DONE_MSVC_INVAL; - - if (handle == INVALID_HANDLE_VALUE) + if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE) { errno = EBADF; return -1; diff --git a/lib/error.c b/lib/error.c index 7482baacf..5ebe8bff2 100644 --- a/lib/error.c +++ b/lib/error.c @@ -92,6 +92,8 @@ extern void __error_at_line (int status, int errnum, const char *file_name, /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" # endif /* The gnulib override of fcntl is not needed in this file. */ diff --git a/lib/fcntl.c b/lib/fcntl.c index d6a328c1c..92e32eebb 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -37,6 +37,9 @@ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" + /* Upper bound on getdtablesize(). See lib/getdtablesize.c. */ # define OPEN_MAX_MAX 0x10000 diff --git a/lib/flock.c b/lib/flock.c index 8f018e50c..439ff434a 100644 --- a/lib/flock.c +++ b/lib/flock.c @@ -26,15 +26,15 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* _get_osfhandle */ -# include - /* LockFileEx */ # define WIN32_LEAN_AND_MEAN # include # include +/* _get_osfhandle */ +# include "msvc-nothrow.h" + /* Determine the current size of a file. Because the other braindead * APIs we'll call need lower/upper 32 bit pairs, keep the file size * like that too. diff --git a/lib/fsync.c b/lib/fsync.c index f0fc8e5d3..325f2167f 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -27,15 +27,15 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* _get_osfhandle */ -# include - /* FlushFileBuffers */ # define WIN32_LEAN_AND_MEAN # include # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" + int fsync (int fd) { diff --git a/lib/isapipe.c b/lib/isapipe.c index a5349b116..f6e16d16f 100644 --- a/lib/isapipe.c +++ b/lib/isapipe.c @@ -26,12 +26,12 @@ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* Windows platforms. */ -/* Get _get_osfhandle. */ -# include - /* Get GetFileType. */ # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" + int isapipe (int fd) { diff --git a/lib/lseek.c b/lib/lseek.c index e6c21369d..134e8b7d9 100644 --- a/lib/lseek.c +++ b/lib/lseek.c @@ -24,6 +24,8 @@ /* Windows platforms. */ /* Get GetFileType. */ # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #else # include #endif diff --git a/lib/msvc-nothrow.c b/lib/msvc-nothrow.c new file mode 100644 index 000000000..db7263157 --- /dev/null +++ b/lib/msvc-nothrow.c @@ -0,0 +1,50 @@ +/* Wrappers that don't throw invalid parameter notifications + with MSVC runtime libraries. + Copyright (C) 2011 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "msvc-nothrow.h" + +/* Get declarations of the Win32 API functions. */ +#define WIN32_LEAN_AND_MEAN +#include + +#include "msvc-inval.h" + +#undef _get_osfhandle + +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +intptr_t +_gl_nothrow_get_osfhandle (int fd) +{ + intptr_t result; + + TRY_MSVC_INVAL + { + result = _get_osfhandle (fd); + } + CATCH_MSVC_INVAL + { + result = INVALID_HANDLE_VALUE; + } + DONE_MSVC_INVAL; + + return result; +} +#endif diff --git a/lib/msvc-nothrow.h b/lib/msvc-nothrow.h new file mode 100644 index 000000000..1ec2888f8 --- /dev/null +++ b/lib/msvc-nothrow.h @@ -0,0 +1,44 @@ +/* Wrappers that don't throw invalid parameter notifications + with MSVC runtime libraries. + Copyright (C) 2011 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _MSVC_NOTHROW_H +#define _MSVC_NOTHROW_H + +/* With MSVC runtime libraries with the "invalid parameter handler" concept, + functions like fprintf(), dup2(), or close() crash when the caller passes + an invalid argument. But POSIX wants error codes (such as EINVAL or EBADF) + instead. + This file defines wrappers that turn such an invalid parameter notification + into an error code. */ + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +/* Get original declaration of _get_osfhandle. */ +# include + +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER + +/* Override _get_osfhandle. */ +extern intptr_t _gl_nothrow_get_osfhandle (int fd); +# define _get_osfhandle _gl_nothrow_get_osfhandle + +# endif + +#endif + +#endif /* _MSVC_NOTHROW_H */ diff --git a/lib/nonblocking.c b/lib/nonblocking.c index 9f7bce916..c356f3621 100644 --- a/lib/nonblocking.c +++ b/lib/nonblocking.c @@ -32,6 +32,8 @@ # define WIN32_LEAN_AND_MEAN # include +# include "msvc-nothrow.h" + int get_nonblocking_flag (int desc) { diff --git a/lib/poll.c b/lib/poll.c index e06456581..b012ba035 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -43,6 +43,7 @@ # include # include # include +# include "msvc-nothrow.h" #else # include # include diff --git a/lib/read.c b/lib/read.c index 21b90db67..61675af0d 100644 --- a/lib/read.c +++ b/lib/read.c @@ -31,6 +31,8 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include +# include "msvc-nothrow.h" + ssize_t rpl_read (int fd, void *buf, size_t count) #undef read diff --git a/lib/select.c b/lib/select.c index 4848859c2..aee0ac2cd 100644 --- a/lib/select.c +++ b/lib/select.c @@ -37,6 +37,8 @@ #include #include +#include "msvc-nothrow.h" + struct bitset { unsigned char in[FD_SETSIZE / CHAR_BIT]; unsigned char out[FD_SETSIZE / CHAR_BIT]; diff --git a/lib/sockets.c b/lib/sockets.c index 53cb66e46..39939b0a3 100644 --- a/lib/sockets.c +++ b/lib/sockets.c @@ -28,6 +28,7 @@ # include # include "fd-hook.h" +# include "msvc-nothrow.h" /* Get set_winsock_errno, FD_TO_SOCKET etc. */ # include "w32sock.h" diff --git a/lib/sockets.h b/lib/sockets.h index 93ae5d280..323f68cd1 100644 --- a/lib/sockets.h +++ b/lib/sockets.h @@ -36,6 +36,8 @@ int gl_sockets_cleanup (void); #include +#include "msvc-nothrow.h" + static inline SOCKET gl_fd_to_handle (int fd) { diff --git a/lib/stdio-read.c b/lib/stdio-read.c index d7901dd67..86b1d616d 100644 --- a/lib/stdio-read.c +++ b/lib/stdio-read.c @@ -37,6 +37,8 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include +# include "msvc-nothrow.h" + # define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \ if (ferror (stream)) \ return (EXPRESSION); \ diff --git a/lib/stdio-write.c b/lib/stdio-write.c index a586c3512..02aed456f 100644 --- a/lib/stdio-write.c +++ b/lib/stdio-write.c @@ -39,6 +39,8 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include +# include "msvc-nothrow.h" + # if GNULIB_NONBLOCKING # define CLEAR_ERRNO \ errno = 0; diff --git a/lib/w32sock.h b/lib/w32sock.h index 651a76df6..55280d649 100644 --- a/lib/w32sock.h +++ b/lib/w32sock.h @@ -22,9 +22,12 @@ /* Get O_RDWR and O_BINARY. */ #include -/* Get _get_osfhandle() and _open_osfhandle(). */ +/* Get _open_osfhandle(). */ #include +/* Get _get_osfhandle(). */ +#include "msvc-nothrow.h" + #define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd))) #define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY)) diff --git a/lib/w32spawn.h b/lib/w32spawn.h index 58b0392c4..166737032 100644 --- a/lib/w32spawn.h +++ b/lib/w32spawn.h @@ -19,7 +19,7 @@ #define WIN32_LEAN_AND_MEAN #include -/* Get _get_osfhandle() and _open_osfhandle(). */ +/* Get _open_osfhandle(). */ #include #include @@ -27,6 +27,9 @@ #include #include +/* Get _get_osfhandle(). */ +#include "msvc-nothrow.h" + #include "cloexec.h" #include "xalloc.h" diff --git a/lib/write.c b/lib/write.c index b0ffa94e9..64bc5352e 100644 --- a/lib/write.c +++ b/lib/write.c @@ -38,6 +38,8 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include +# include "msvc-nothrow.h" + ssize_t rpl_write (int fd, const void *buf, size_t count) #undef write diff --git a/m4/msvc-nothrow.m4 b/m4/msvc-nothrow.m4 new file mode 100644 index 000000000..b2f6bb49a --- /dev/null +++ b/m4/msvc-nothrow.m4 @@ -0,0 +1,10 @@ +# msvc-nothrow.m4 serial 1 +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, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_MSVC_NOTHROW], +[ + AC_REQUIRE([gl_MSVC_INVAL]) +]) diff --git a/modules/accept b/modules/accept index 6421e92d5..059a56d29 100644 --- a/modules/accept +++ b/modules/accept @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/accept4 b/modules/accept4 index e6b999415..e9319763c 100644 --- a/modules/accept4 +++ b/modules/accept4 @@ -12,6 +12,7 @@ accept fcntl-h binary-io extensions +msvc-nothrow configure.ac: gl_FUNC_ACCEPT4 diff --git a/modules/bind b/modules/bind index dd211d45a..e46bd267a 100644 --- a/modules/bind +++ b/modules/bind @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/cloexec-tests b/modules/cloexec-tests index 3a76b9e9a..524716c92 100644 --- a/modules/cloexec-tests +++ b/modules/cloexec-tests @@ -4,6 +4,7 @@ tests/macros.h Depends-on: binary-io +msvc-nothrow configure.ac: diff --git a/modules/connect b/modules/connect index d5958434e..c77632ca6 100644 --- a/modules/connect +++ b/modules/connect @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/dup2 b/modules/dup2 index 2317db3cd..2ad65d1dc 100644 --- a/modules/dup2 +++ b/modules/dup2 @@ -9,6 +9,7 @@ Depends-on: unistd dup2-obsolete msvc-inval [test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1] +msvc-nothrow [test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1] configure.ac: gl_FUNC_DUP2 diff --git a/modules/dup2-tests b/modules/dup2-tests index a973fd75e..8277e3b17 100644 --- a/modules/dup2-tests +++ b/modules/dup2-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: binary-io +msvc-nothrow open configure.ac: diff --git a/modules/dup3-tests b/modules/dup3-tests index 26dd5d89a..02f422e84 100644 --- a/modules/dup3-tests +++ b/modules/dup3-tests @@ -4,6 +4,7 @@ tests/signature.h tests/macros.h Depends-on: +msvc-nothrow open configure.ac: diff --git a/modules/error b/modules/error index ae12b45ad..f8676176b 100644 --- a/modules/error +++ b/modules/error @@ -14,6 +14,7 @@ m4/error.m4 Depends-on: strerror [test $ac_cv_lib_error_at_line = no] unistd [test $ac_cv_lib_error_at_line = no] +msvc-nothrow [test $ac_cv_lib_error_at_line = no] configure.ac: gl_ERROR diff --git a/modules/execute b/modules/execute index a65696bb5..f4584ab1a 100644 --- a/modules/execute +++ b/modules/execute @@ -14,6 +14,7 @@ error fatal-signal wait-process gettext-h +msvc-nothrow spawn posix_spawnp posix_spawn_file_actions_init diff --git a/modules/fcntl b/modules/fcntl index 4c30e9e4a..ab7c8ad6b 100644 --- a/modules/fcntl +++ b/modules/fcntl @@ -10,6 +10,7 @@ fcntl-h extensions dup2 [test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1] getdtablesize [test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1] +msvc-nothrow [test $HAVE_FCNTL = 0 || test $REPLACE_FCNTL = 1] configure.ac: gl_FUNC_FCNTL diff --git a/modules/fcntl-tests b/modules/fcntl-tests index 44b040c25..72705801e 100644 --- a/modules/fcntl-tests +++ b/modules/fcntl-tests @@ -6,6 +6,7 @@ tests/macros.h Depends-on: binary-io getdtablesize +msvc-nothrow stdbool configure.ac: diff --git a/modules/flock b/modules/flock index 56ef9b264..73d27c622 100644 --- a/modules/flock +++ b/modules/flock @@ -7,6 +7,7 @@ m4/flock.m4 Depends-on: sys_file +msvc-nothrow [test $HAVE_FLOCK = 0] configure.ac: gl_FUNC_FLOCK diff --git a/modules/fsync b/modules/fsync index 0f5b3fc79..660eb59bc 100644 --- a/modules/fsync +++ b/modules/fsync @@ -7,6 +7,7 @@ m4/fsync.m4 Depends-on: unistd +msvc-nothrow [test $HAVE_FSYNC = 0] configure.ac: gl_FUNC_FSYNC diff --git a/modules/gethostname b/modules/gethostname index 42ee838e0..b41dfad9a 100644 --- a/modules/gethostname +++ b/modules/gethostname @@ -11,6 +11,7 @@ unistd sys_socket [test $HAVE_GETHOSTNAME = 0] errno [test $HAVE_GETHOSTNAME = 0] sockets [test $HAVE_GETHOSTNAME = 0] +msvc-nothrow [test $HAVE_GETHOSTNAME = 0] configure.ac: gl_FUNC_GETHOSTNAME diff --git a/modules/getpeername b/modules/getpeername index b7f04ee28..d1ef82272 100644 --- a/modules/getpeername +++ b/modules/getpeername @@ -10,6 +10,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/getsockname b/modules/getsockname index 033c17082..15cf490ca 100644 --- a/modules/getsockname +++ b/modules/getsockname @@ -10,6 +10,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/getsockopt b/modules/getsockopt index d13e064ed..1cd1f2e12 100644 --- a/modules/getsockopt +++ b/modules/getsockopt @@ -10,6 +10,7 @@ sys_socket socketlib sys_time [test "$ac_cv_header_winsock2_h" = yes] errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/ioctl b/modules/ioctl index 9842a53f9..ba4a85a32 100644 --- a/modules/ioctl +++ b/modules/ioctl @@ -11,6 +11,7 @@ sys_ioctl sys_socket [test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1] errno [test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1] fd-hook [test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1] +msvc-nothrow [test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1] configure.ac: gl_FUNC_IOCTL diff --git a/modules/isapipe b/modules/isapipe index cc62ea8ce..945df3ed8 100644 --- a/modules/isapipe +++ b/modules/isapipe @@ -10,6 +10,7 @@ Depends-on: stdbool [test $HAVE_ISAPIPE = 0] sys_stat [test $HAVE_ISAPIPE = 0] unistd [test $HAVE_ISAPIPE = 0] +msvc-nothrow [test $HAVE_ISAPIPE = 0] configure.ac: gl_ISAPIPE diff --git a/modules/listen b/modules/listen index 8aff376c3..baaadc21a 100644 --- a/modules/listen +++ b/modules/listen @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/lseek b/modules/lseek index 0fc7923f6..c43027354 100644 --- a/modules/lseek +++ b/modules/lseek @@ -8,6 +8,7 @@ m4/lseek.m4 Depends-on: unistd largefile +msvc-nothrow [test $REPLACE_LSEEK = 1] configure.ac: gl_FUNC_LSEEK diff --git a/modules/msvc-nothrow b/modules/msvc-nothrow new file mode 100644 index 000000000..46d71aae4 --- /dev/null +++ b/modules/msvc-nothrow @@ -0,0 +1,28 @@ +Description: +wrappers that don't throw invalid parameter notifications with MSVC runtime +libraries + +Files: +lib/msvc-nothrow.h +lib/msvc-nothrow.c +m4/msvc-nothrow.m4 + +Depends-on: +msvc-inval + +configure.ac: +gl_MSVC_NOTHROW +if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + AC_LIBOBJ([msvc-nothrow]) +fi + +Makefile.am: + +Include: +"msvc-nothrow.h" + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/modules/nonblocking b/modules/nonblocking index 2d469ebaa..96881f5b5 100644 --- a/modules/nonblocking +++ b/modules/nonblocking @@ -12,6 +12,7 @@ m4/asm-underscore.m4 Depends-on: fcntl-h ioctl +msvc-nothrow stdbool stdio sys_socket diff --git a/modules/pipe-posix-tests b/modules/pipe-posix-tests index 7afafdc50..3f428a061 100644 --- a/modules/pipe-posix-tests +++ b/modules/pipe-posix-tests @@ -6,6 +6,7 @@ tests/macros.h Depends-on: stdbool binary-io +msvc-nothrow configure.ac: diff --git a/modules/pipe2-tests b/modules/pipe2-tests index 2e6c3f78a..74f9d5f3e 100644 --- a/modules/pipe2-tests +++ b/modules/pipe2-tests @@ -5,6 +5,7 @@ tests/macros.h Depends-on: stdbool +msvc-nothrow configure.ac: diff --git a/modules/poll b/modules/poll index f1f22bfd8..37143320e 100644 --- a/modules/poll +++ b/modules/poll @@ -12,6 +12,7 @@ select [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1] sys_select [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1] sys_time [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1] errno [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1] +msvc-nothrow [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1] configure.ac: gl_FUNC_POLL diff --git a/modules/read b/modules/read index 12d97c75f..d72595583 100644 --- a/modules/read +++ b/modules/read @@ -7,6 +7,7 @@ m4/read.m4 Depends-on: unistd +msvc-nothrow [test $REPLACE_READ = 1] configure.ac: gl_FUNC_READ diff --git a/modules/recv b/modules/recv index 731717bc3..b47d8f532 100644 --- a/modules/recv +++ b/modules/recv @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/recvfrom b/modules/recvfrom index c4749ae45..2b051b461 100644 --- a/modules/recvfrom +++ b/modules/recvfrom @@ -10,6 +10,7 @@ sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] getpeername [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/select b/modules/select index f665740b0..7b25a8bc9 100644 --- a/modules/select +++ b/modules/select @@ -9,6 +9,7 @@ Depends-on: sys_select alloca [test $REPLACE_SELECT = 1] sockets [test $REPLACE_SELECT = 1] +msvc-nothrow [test $REPLACE_SELECT = 1] configure.ac: gl_FUNC_SELECT diff --git a/modules/send b/modules/send index 18d6c0d14..5e115c3f8 100644 --- a/modules/send +++ b/modules/send @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/sendto b/modules/sendto index 847699de4..924818e31 100644 --- a/modules/sendto +++ b/modules/sendto @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/setsockopt b/modules/setsockopt index 0b4ae4955..bfe8acdae 100644 --- a/modules/setsockopt +++ b/modules/setsockopt @@ -10,6 +10,7 @@ sys_socket socketlib sys_time [test "$ac_cv_header_winsock2_h" = yes] errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/shutdown b/modules/shutdown index 7c76ba531..32845dbc8 100644 --- a/modules/shutdown +++ b/modules/shutdown @@ -9,6 +9,7 @@ Depends-on: sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/sigpipe b/modules/sigpipe index 4f03c9e14..d28a562af 100644 --- a/modules/sigpipe +++ b/modules/sigpipe @@ -12,6 +12,7 @@ lib/stdio-write.c m4/asm-underscore.m4 Depends-on: +msvc-nothrow raise signal sigprocmask diff --git a/modules/socket b/modules/socket index 6a056e423..49625494a 100644 --- a/modules/socket +++ b/modules/socket @@ -10,6 +10,7 @@ sys_socket socketlib errno [test "$ac_cv_header_winsock2_h" = yes] sockets [test "$ac_cv_header_winsock2_h" = yes] +msvc-nothrow [test "$ac_cv_header_winsock2_h" = yes] configure.ac: AC_REQUIRE([gl_HEADER_SYS_SOCKET]) diff --git a/modules/sockets b/modules/sockets index fe9292631..b6dffabc1 100644 --- a/modules/sockets +++ b/modules/sockets @@ -11,6 +11,7 @@ Depends-on: socketlib sys_socket fd-hook +msvc-nothrow configure.ac: gl_SOCKETS diff --git a/modules/spawn-pipe b/modules/spawn-pipe index 9898b3759..bcb0c9d25 100644 --- a/modules/spawn-pipe +++ b/modules/spawn-pipe @@ -14,6 +14,7 @@ environ error fatal-signal gettext-h +msvc-nothrow open pipe2 pipe2-safer diff --git a/modules/unistd-safer-tests b/modules/unistd-safer-tests index cc4b97ab3..d8519a656 100644 --- a/modules/unistd-safer-tests +++ b/modules/unistd-safer-tests @@ -6,6 +6,7 @@ Depends-on: binary-io cloexec fd-safer-flag +msvc-nothrow stdbool configure.ac: diff --git a/modules/write b/modules/write index d60b5a7f6..c19f73b7e 100644 --- a/modules/write +++ b/modules/write @@ -8,6 +8,7 @@ m4/write.m4 Depends-on: unistd raise [test $REPLACE_WRITE = 1] +msvc-nothrow [test $REPLACE_WRITE = 1] configure.ac: gl_FUNC_WRITE diff --git a/tests/test-cloexec.c b/tests/test-cloexec.c index 374de3038..c1473d515 100644 --- a/tests/test-cloexec.c +++ b/tests/test-cloexec.c @@ -28,6 +28,8 @@ /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c index 14cfafffe..5cb45f5fd 100644 --- a/tests/test-dup-safer.c +++ b/tests/test-dup-safer.c @@ -32,6 +32,8 @@ /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #if !O_BINARY diff --git a/tests/test-dup2.c b/tests/test-dup2.c index 37454e965..a14807a36 100644 --- a/tests/test-dup2.c +++ b/tests/test-dup2.c @@ -36,6 +36,8 @@ SIGNATURE_CHECK (dup2, int, (int, int)); /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "macros.h" diff --git a/tests/test-dup3.c b/tests/test-dup3.c index ed3a88f41..033193df6 100644 --- a/tests/test-dup3.c +++ b/tests/test-dup3.c @@ -32,6 +32,8 @@ SIGNATURE_CHECK (dup3, int, (int, int, int)); /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c index 59b007719..c6066ead1 100644 --- a/tests/test-fcntl.c +++ b/tests/test-fcntl.c @@ -34,6 +34,8 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...)); /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" diff --git a/tests/test-pipe.c b/tests/test-pipe.c index 5302c3ece..90f41f910 100644 --- a/tests/test-pipe.c +++ b/tests/test-pipe.c @@ -29,6 +29,8 @@ SIGNATURE_CHECK (pipe, int, (int[2])); /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" diff --git a/tests/test-pipe2.c b/tests/test-pipe2.c index d83162c2f..c278f7aaf 100644 --- a/tests/test-pipe2.c +++ b/tests/test-pipe2.c @@ -29,6 +29,8 @@ SIGNATURE_CHECK (pipe2, int, (int[2], int)); /* Get declarations of the Win32 API functions. */ # define WIN32_LEAN_AND_MEAN # include +/* Get _get_osfhandle. */ +# include "msvc-nothrow.h" #endif #include "binary-io.h" -- 2.11.0