From 03c3f38b55d6654263f924f35145cbb9add4e77d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 10 May 2017 21:52:21 +0200 Subject: [PATCH] Implement a way to opt out from MSVC support. This is useful for Emacs. * modules/msvc-nothrow (configure.ac): Invoke gl_MODULE_INDICATOR. * lib/accept4.c: Include as an alternative to msvc-nothrow.h. * lib/error.c: Likewise. * lib/fcntl.c: Likewise. * lib/flock.c: Likewise. * lib/fstat.c: Likewise. * lib/fsync.c: Likewise. * lib/ioctl.c: Likewise. * lib/isapipe.c: Likewise. * lib/lseek.c: Likewise. * lib/nonblocking.c: Likewise. * lib/poll.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/utimens.c: Likewise. * lib/w32sock.h: Likewise. * lib/w32spawn.h: Likewise. * tests/test-cloexec.c: Likewise. * 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. * lib/ftruncate.c: Likewise. (chsize_nothrow): Renamed from chsize. * lib/msvc-nothrow.c: Don't include msvc-inval.h if HAVE_MSVC_INVALID_PARAMETER_HANDLER is not defined. * lib/close.c: Likewise. * lib/dup.c: Likewise. * lib/fclose.c: Likewise. * lib/raise.c: Likewise. * tests/test-fgetc.c: Likewise. * tests/test-fputc.c: Likewise. * tests/test-fread.c: Likewise. * tests/test-fwrite.c: Likewise. * lib/getdtablesize.c: Likewise. (_setmaxstdio_nothrow): Renamed from _setmaxstdio. * lib/isatty.c: Don't include msvc-inval.h if HAVE_MSVC_INVALID_PARAMETER_HANDLER is not defined. Include as an alternative to msvc-nothrow.h. * lib/read.c: Likewise. * lib/write.c: Likewise. * lib/dup2.c: Likewise. (dup2_nothrow): New function. (ms_windows_dup2): Use it. * m4/close.m4 (gl_FUNC_CLOSE): Invoke gl_MSVC_INVAL and test HAVE_MSVC_INVALID_PARAMETER_HANDLER only if gl_MSVC_INVAL is defined. * m4/dup.m4 (gl_FUNC_DUP): Likewise. * m4/fdopen.m4 (gl_FUNC_FDOPEN): Likewise. * m4/raise.m4 (gl_FUNC_RAISE): Likewise. * m4/read.m4 (gl_FUNC_READ): Likewise. * m4/write.m4 (gl_FUNC_WRITE): Likewise. * doc/windows-without-msvc.texi: New file. * doc/gnulib.texi (Native Windows Support without MSVC Support): New section. --- ChangeLog | 64 +++++++++++++++++++++++++++++++++++ doc/gnulib.texi | 3 ++ doc/windows-without-msvc.texi | 8 +++++ lib/accept4.c | 6 +++- lib/close.c | 4 ++- lib/dup.c | 4 ++- lib/dup2.c | 44 +++++++++++++++++------- lib/error.c | 6 +++- lib/fclose.c | 4 ++- lib/fcntl.c | 6 +++- lib/flock.c | 6 +++- lib/fstat.c | 6 +++- lib/fsync.c | 6 +++- lib/ftruncate.c | 11 ++++-- lib/getdtablesize.c | 11 +++--- lib/ioctl.c | 6 +++- lib/isapipe.c | 6 +++- lib/isatty.c | 10 ++++-- lib/lseek.c | 6 +++- lib/msvc-nothrow.c | 4 ++- lib/nonblocking.c | 6 +++- lib/poll.c | 6 +++- lib/raise.c | 4 ++- lib/read.c | 10 ++++-- lib/select.c | 6 +++- lib/sockets.c | 6 +++- lib/sockets.h | 12 ++++--- lib/stdio-read.c | 6 +++- lib/stdio-write.c | 6 +++- lib/utimens.c | 6 +++- lib/w32sock.h | 6 +++- lib/w32spawn.h | 6 +++- lib/write.c | 10 ++++-- m4/close.m4 | 12 ++++--- m4/dup.m4 | 12 ++++--- m4/fdopen.m4 | 13 ++++--- m4/raise.m4 | 12 ++++--- m4/read.m4 | 12 ++++--- m4/write.m4 | 12 ++++--- modules/msvc-nothrow | 1 + tests/test-cloexec.c | 6 +++- tests/test-dup-safer.c | 6 +++- tests/test-dup2.c | 6 +++- tests/test-dup3.c | 6 +++- tests/test-fcntl.c | 6 +++- tests/test-fgetc.c | 4 ++- tests/test-fputc.c | 4 ++- tests/test-fread.c | 4 ++- tests/test-fwrite.c | 4 ++- tests/test-pipe.c | 6 +++- tests/test-pipe2.c | 6 +++- 51 files changed, 350 insertions(+), 93 deletions(-) create mode 100644 doc/windows-without-msvc.texi diff --git a/ChangeLog b/ChangeLog index 1807004a29..35cd42058f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,67 @@ +2017-05-10 Bruno Haible + + Implement a way to opt out from MSVC support. + This is useful for Emacs. + * modules/msvc-nothrow (configure.ac): Invoke gl_MODULE_INDICATOR. + * lib/accept4.c: Include as an alternative to msvc-nothrow.h. + * lib/error.c: Likewise. + * lib/fcntl.c: Likewise. + * lib/flock.c: Likewise. + * lib/fstat.c: Likewise. + * lib/fsync.c: Likewise. + * lib/ioctl.c: Likewise. + * lib/isapipe.c: Likewise. + * lib/lseek.c: Likewise. + * lib/nonblocking.c: Likewise. + * lib/poll.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/utimens.c: Likewise. + * lib/w32sock.h: Likewise. + * lib/w32spawn.h: Likewise. + * tests/test-cloexec.c: Likewise. + * 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. + * lib/ftruncate.c: Likewise. + (chsize_nothrow): Renamed from chsize. + * lib/msvc-nothrow.c: Don't include msvc-inval.h if + HAVE_MSVC_INVALID_PARAMETER_HANDLER is not defined. + * lib/close.c: Likewise. + * lib/dup.c: Likewise. + * lib/fclose.c: Likewise. + * lib/raise.c: Likewise. + * tests/test-fgetc.c: Likewise. + * tests/test-fputc.c: Likewise. + * tests/test-fread.c: Likewise. + * tests/test-fwrite.c: Likewise. + * lib/getdtablesize.c: Likewise. + (_setmaxstdio_nothrow): Renamed from _setmaxstdio. + * lib/isatty.c: Don't include msvc-inval.h if + HAVE_MSVC_INVALID_PARAMETER_HANDLER is not defined. + Include as an alternative to msvc-nothrow.h. + * lib/read.c: Likewise. + * lib/write.c: Likewise. + * lib/dup2.c: Likewise. + (dup2_nothrow): New function. + (ms_windows_dup2): Use it. + * m4/close.m4 (gl_FUNC_CLOSE): Invoke gl_MSVC_INVAL and test + HAVE_MSVC_INVALID_PARAMETER_HANDLER only if gl_MSVC_INVAL is defined. + * m4/dup.m4 (gl_FUNC_DUP): Likewise. + * m4/fdopen.m4 (gl_FUNC_FDOPEN): Likewise. + * m4/raise.m4 (gl_FUNC_RAISE): Likewise. + * m4/read.m4 (gl_FUNC_READ): Likewise. + * m4/write.m4 (gl_FUNC_WRITE): Likewise. + * doc/windows-without-msvc.texi: New file. + * doc/gnulib.texi (Native Windows Support without MSVC Support): New + section. + 2017-05-10 Bruno Haible wait-process: Adjust native Windows support. diff --git a/doc/gnulib.texi b/doc/gnulib.texi index 378cee642f..d23ab9c068 100644 --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -6324,12 +6324,15 @@ to POSIX that it can be treated like any other Unix-like platform. @menu * Libtool and Windows:: * Windows sockets:: +* Native Windows Support without MSVC Support:: @end menu @include windows-libtool.texi @include windows-sockets.texi +@include windows-without-msvc.texi + @node Particular Modules @chapter Particular Modules diff --git a/doc/windows-without-msvc.texi b/doc/windows-without-msvc.texi new file mode 100644 index 0000000000..781612b802 --- /dev/null +++ b/doc/windows-without-msvc.texi @@ -0,0 +1,8 @@ +@node Native Windows Support without MSVC Support +@section Native Windows Support without MSVC Support + +If your package does not desire to have MSVC support, that is, if MinGW +shall be the only native Windows platform that you wish to get support +for from Gnulib, and you wish to minimize the number of files imported +from Gnulib accordingly, you can do so by passing the options +@samp{--avoid=msvc-inval --avoid=msvc-nothrow} to @code{gnulib-tool}. diff --git a/lib/accept4.c b/lib/accept4.c index 040fb9ff6a..997f75ad8b 100644 --- a/lib/accept4.c +++ b/lib/accept4.c @@ -22,7 +22,11 @@ #include #include #include "binary-io.h" -#include "msvc-nothrow.h" +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif #ifndef SOCK_CLOEXEC # define SOCK_CLOEXEC 0 diff --git a/lib/close.c b/lib/close.c index 3e451871f5..6a72c32299 100644 --- a/lib/close.c +++ b/lib/close.c @@ -22,7 +22,9 @@ #include #include "fd-hook.h" -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #undef close diff --git a/lib/dup.c b/lib/dup.c index 819e9e3780..69887b0c35 100644 --- a/lib/dup.c +++ b/lib/dup.c @@ -22,7 +22,9 @@ #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #undef dup diff --git a/lib/dup2.c b/lib/dup2.c index c0c7cadf4a..002dc8c76c 100644 --- a/lib/dup2.c +++ b/lib/dup2.c @@ -35,10 +35,39 @@ # define WIN32_LEAN_AND_MEAN # include -# include "msvc-inval.h" +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +# endif /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif + +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static int +dup2_nothrow (int fd, int desired_fd) +{ + int result; + + TRY_MSVC_INVAL + { + result = dup2 (fd, desired_fd); + } + CATCH_MSVC_INVAL + { + errno = EBADF; + result = -1; + } + DONE_MSVC_INVAL; + + return result; +} +# else +# define dup2_nothrow dup2 +# endif static int ms_windows_dup2 (int fd, int desired_fd) @@ -66,16 +95,7 @@ ms_windows_dup2 (int fd, int desired_fd) return -1; } - TRY_MSVC_INVAL - { - result = dup2 (fd, desired_fd); - } - CATCH_MSVC_INVAL - { - errno = EBADF; - result = -1; - } - DONE_MSVC_INVAL; + result = dup2_nothrow (fd, desired_fd); if (result == 0) result = desired_fd; diff --git a/lib/error.c b/lib/error.c index ed9b37a955..418d1ab8de 100644 --- a/lib/error.c +++ b/lib/error.c @@ -98,7 +98,11 @@ extern void __error_at_line (int status, int errnum, const char *file_name, # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # endif /* The gnulib override of fcntl is not needed in this file. */ diff --git a/lib/fclose.c b/lib/fclose.c index facff2bd85..fc6f6087b3 100644 --- a/lib/fclose.c +++ b/lib/fclose.c @@ -23,7 +23,9 @@ #include #include "freading.h" -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #undef fclose diff --git a/lib/fcntl.c b/lib/fcntl.c index afe15468ff..d4dd144e05 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c @@ -38,7 +38,11 @@ # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif /* Upper bound on getdtablesize(). See lib/getdtablesize.c. */ # define OPEN_MAX_MAX 0x10000 diff --git a/lib/flock.c b/lib/flock.c index 7698e43ffc..0c55d521cf 100644 --- a/lib/flock.c +++ b/lib/flock.c @@ -33,7 +33,11 @@ # include /* _get_osfhandle */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif /* 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 diff --git a/lib/fstat.c b/lib/fstat.c index a4896e3a77..605ac7d85e 100644 --- a/lib/fstat.c +++ b/lib/fstat.c @@ -56,7 +56,11 @@ orig_fstat (int fd, struct stat *buf) #ifdef WINDOWS_NATIVE # define WIN32_LEAN_AND_MEAN # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # include "stat-w32.h" #endif diff --git a/lib/fsync.c b/lib/fsync.c index d7de6d8b19..846f308720 100644 --- a/lib/fsync.c +++ b/lib/fsync.c @@ -34,7 +34,11 @@ # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif int fsync (int fd) diff --git a/lib/ftruncate.c b/lib/ftruncate.c index 913df19cbc..f0ecae27b4 100644 --- a/lib/ftruncate.c +++ b/lib/ftruncate.c @@ -38,7 +38,11 @@ # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif static BOOL SetFileSize (HANDLE h, LONGLONG size) @@ -175,13 +179,14 @@ chsize_nothrow (int fd, long length) return result; } -# define chsize chsize_nothrow +# else +# define chsize_nothrow chsize # endif int ftruncate (int fd, off_t length) { - return chsize (fd, length); + return chsize_nothrow (fd, length); } # endif diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c index 7fabb51e2c..c356cf4aa9 100644 --- a/lib/getdtablesize.c +++ b/lib/getdtablesize.c @@ -24,7 +24,9 @@ # include -# include "msvc-inval.h" +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +# endif # if HAVE_MSVC_INVALID_PARAMETER_HANDLER static int @@ -44,7 +46,8 @@ _setmaxstdio_nothrow (int newmax) return result; } -# define _setmaxstdio _setmaxstdio_nothrow +# else +# define _setmaxstdio_nothrow _setmaxstdio # endif /* Cache for the previous getdtablesize () result. Safe to cache because @@ -76,9 +79,9 @@ getdtablesize (void) freed when we call _setmaxstdio with the original value. */ int orig_max_stdio = _getmaxstdio (); unsigned int bound; - for (bound = 0x10000; _setmaxstdio (bound) < 0; bound = bound / 2) + for (bound = 0x10000; _setmaxstdio_nothrow (bound) < 0; bound = bound / 2) ; - _setmaxstdio (orig_max_stdio); + _setmaxstdio_nothrow (orig_max_stdio); dtablesize = bound; } return dtablesize; diff --git a/lib/ioctl.c b/lib/ioctl.c index a28a3ae437..f1425589cf 100644 --- a/lib/ioctl.c +++ b/lib/ioctl.c @@ -52,7 +52,11 @@ rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */) # include "fd-hook.h" /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif static int primary_ioctl (int fd, int request, void *arg) diff --git a/lib/isapipe.c b/lib/isapipe.c index dbc63b5f49..535ece933b 100644 --- a/lib/isapipe.c +++ b/lib/isapipe.c @@ -30,7 +30,11 @@ # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif int isapipe (int fd) diff --git a/lib/isatty.c b/lib/isatty.c index f050426c5f..dba4380561 100644 --- a/lib/isatty.c +++ b/lib/isatty.c @@ -27,10 +27,16 @@ #define WIN32_LEAN_AND_MEAN #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif /* Get _get_osfhandle(). */ -#include "msvc-nothrow.h" +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif static BOOL IsConsoleHandle (HANDLE h) { diff --git a/lib/lseek.c b/lib/lseek.c index e603539b36..9c991a3d30 100644 --- a/lib/lseek.c +++ b/lib/lseek.c @@ -24,7 +24,11 @@ /* Get GetFileType. */ # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #else # include #endif diff --git a/lib/msvc-nothrow.c b/lib/msvc-nothrow.c index 300ed41aaf..86a88082ff 100644 --- a/lib/msvc-nothrow.c +++ b/lib/msvc-nothrow.c @@ -24,7 +24,9 @@ #define WIN32_LEAN_AND_MEAN #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #undef _get_osfhandle diff --git a/lib/nonblocking.c b/lib/nonblocking.c index 3d031aa834..b9ed86a8ba 100644 --- a/lib/nonblocking.c +++ b/lib/nonblocking.c @@ -32,7 +32,11 @@ # define WIN32_LEAN_AND_MEAN # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif int get_nonblocking_flag (int desc) diff --git a/lib/poll.c b/lib/poll.c index 078b1bab41..9115bcd4a9 100644 --- a/lib/poll.c +++ b/lib/poll.c @@ -41,7 +41,11 @@ # include # include # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #else # include # include diff --git a/lib/raise.c b/lib/raise.c index d3325a630e..0a6d8ca9d8 100644 --- a/lib/raise.c +++ b/lib/raise.c @@ -27,7 +27,9 @@ # include -# include "msvc-inval.h" +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +# endif # undef raise diff --git a/lib/read.c b/lib/read.c index 08108f7f7b..a9b943ff90 100644 --- a/lib/read.c +++ b/lib/read.c @@ -28,8 +28,14 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include -# include "msvc-inval.h" -# include "msvc-nothrow.h" +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +# endif +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # undef read diff --git a/lib/select.c b/lib/select.c index ac86c499d4..01b19823fb 100644 --- a/lib/select.c +++ b/lib/select.c @@ -39,7 +39,11 @@ /* Get the overridden 'struct timeval'. */ #include -#include "msvc-nothrow.h" +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif #undef select diff --git a/lib/sockets.c b/lib/sockets.c index 9333ee4dd8..028e20ec0e 100644 --- a/lib/sockets.c +++ b/lib/sockets.c @@ -28,7 +28,11 @@ # include # include "fd-hook.h" -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif /* Get set_winsock_errno, FD_TO_SOCKET etc. */ # include "w32sock.h" diff --git a/lib/sockets.h b/lib/sockets.h index 8392e57566..23ad74d2fa 100644 --- a/lib/sockets.h +++ b/lib/sockets.h @@ -18,7 +18,7 @@ /* Written by Simon Josefsson */ #ifndef SOCKETS_H -# define SOCKETS_H 1 +#define SOCKETS_H 1 #define SOCKETS_1_0 0x0001 #define SOCKETS_1_1 0x0101 @@ -43,9 +43,13 @@ int gl_sockets_cleanup (void) other library that only accepts sockets. */ #ifdef WINDOWS_SOCKETS -#include +# include -#include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif static inline SOCKET gl_fd_to_handle (int fd) @@ -55,7 +59,7 @@ gl_fd_to_handle (int fd) #else -#define gl_fd_to_handle(x) (x) +# define gl_fd_to_handle(x) (x) #endif /* WINDOWS_SOCKETS */ diff --git a/lib/stdio-read.c b/lib/stdio-read.c index 8caf2f003c..98db74966e 100644 --- a/lib/stdio-read.c +++ b/lib/stdio-read.c @@ -37,7 +37,11 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # define CALL_WITH_ERRNO_FIX(RETTYPE, EXPRESSION, FAILED) \ if (ferror (stream)) \ diff --git a/lib/stdio-write.c b/lib/stdio-write.c index 8ad693bc62..34b22f50ac 100644 --- a/lib/stdio-write.c +++ b/lib/stdio-write.c @@ -39,7 +39,11 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # if GNULIB_NONBLOCKING # define CLEAR_ERRNO \ diff --git a/lib/utimens.c b/lib/utimens.c index b4bfa8e322..ff4eab073c 100644 --- a/lib/utimens.c +++ b/lib/utimens.c @@ -44,7 +44,11 @@ # define USE_SETFILETIME # define WIN32_LEAN_AND_MEAN # include -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif /* Avoid recursion with rpl_futimens or rpl_utimensat. */ diff --git a/lib/w32sock.h b/lib/w32sock.h index 8ac8ab7751..2f753fb4c9 100644 --- a/lib/w32sock.h +++ b/lib/w32sock.h @@ -26,7 +26,11 @@ #include /* Get _get_osfhandle(). */ -#include "msvc-nothrow.h" +#if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +#else +# include +#endif #define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd))) #define SOCKET_TO_FD(fh) (_open_osfhandle ((intptr_t) (fh), O_RDWR | O_BINARY)) diff --git a/lib/w32spawn.h b/lib/w32spawn.h index 7932662700..26ff658aa2 100644 --- a/lib/w32spawn.h +++ b/lib/w32spawn.h @@ -30,7 +30,11 @@ #include /* Get _get_osfhandle(). */ -#include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #include "cloexec.h" #include "xalloc.h" diff --git a/lib/write.c b/lib/write.c index 6a3b623e68..b81db62081 100644 --- a/lib/write.c +++ b/lib/write.c @@ -34,8 +34,14 @@ # define WIN32_LEAN_AND_MEAN /* avoid including junk */ # include -# include "msvc-inval.h" -# include "msvc-nothrow.h" +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +# endif +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif # undef write diff --git a/m4/close.m4 b/m4/close.m4 index 005a43ae1e..ed357ab924 100644 --- a/m4/close.m4 +++ b/m4/close.m4 @@ -1,4 +1,4 @@ -# close.m4 serial 8 +# close.m4 serial 9 dnl Copyright (C) 2008-2017 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,10 +7,12 @@ 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_MSVC_INVAL], [ + 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/m4/dup.m4 b/m4/dup.m4 index 74fa9bd3dc..75307cbb89 100644 --- a/m4/dup.m4 +++ b/m4/dup.m4 @@ -1,4 +1,4 @@ -# dup.m4 serial 4 +# dup.m4 serial 5 dnl Copyright (C) 2011-2017 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,10 +7,12 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_DUP], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - AC_REQUIRE([gl_MSVC_INVAL]) - if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then - REPLACE_DUP=1 - fi + m4_ifdef([gl_MSVC_INVAL], [ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_DUP=1 + fi + ]) dnl Replace dup() for supporting the gnulib-defined fchdir() function, dnl to keep fchdir's bookkeeping up-to-date. m4_ifdef([gl_FUNC_FCHDIR], [ diff --git a/m4/fdopen.m4 b/m4/fdopen.m4 index 8e8619cc8d..42f928efd0 100644 --- a/m4/fdopen.m4 +++ b/m4/fdopen.m4 @@ -1,4 +1,4 @@ -# fdopen.m4 serial 3 +# fdopen.m4 serial 4 dnl Copyright (C) 2011-2017 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,10 +8,13 @@ AC_DEFUN([gl_FUNC_FDOPEN], [ AC_REQUIRE([gl_STDIO_H_DEFAULTS]) AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - AC_REQUIRE([gl_MSVC_INVAL]) - if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then - REPLACE_FDOPEN=1 - else + m4_ifdef([gl_MSVC_INVAL], [ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_FDOPEN=1 + fi + ]) + if test $REPLACE_FDOPEN = 0; then 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], [ diff --git a/m4/raise.m4 b/m4/raise.m4 index 28c2e0b5ce..fe6e06858e 100644 --- a/m4/raise.m4 +++ b/m4/raise.m4 @@ -1,4 +1,4 @@ -# raise.m4 serial 3 +# raise.m4 serial 4 dnl Copyright (C) 2011-2017 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,14 +8,16 @@ AC_DEFUN([gl_FUNC_RAISE], [ AC_REQUIRE([gl_SIGNAL_H_DEFAULTS]) AC_REQUIRE([AC_CANONICAL_HOST]) - AC_REQUIRE([gl_MSVC_INVAL]) AC_CHECK_FUNCS([raise]) if test $ac_cv_func_raise = no; then HAVE_RAISE=0 else - if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then - REPLACE_RAISE=1 - fi + m4_ifdef([gl_MSVC_INVAL], [ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_RAISE=1 + fi + ]) m4_ifdef([gl_SIGNALBLOCKING], [ gl_SIGNALBLOCKING if test $HAVE_POSIX_SIGNALBLOCKING = 0; then diff --git a/m4/read.m4 b/m4/read.m4 index 36249abdcd..24668028ea 100644 --- a/m4/read.m4 +++ b/m4/read.m4 @@ -1,4 +1,4 @@ -# read.m4 serial 4 +# read.m4 serial 5 dnl Copyright (C) 2011-2017 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,10 +7,12 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_READ], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - AC_REQUIRE([gl_MSVC_INVAL]) - if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then - REPLACE_READ=1 - fi + m4_ifdef([gl_MSVC_INVAL], [ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_READ=1 + fi + ]) dnl This ifdef is just an optimization, to avoid performing a configure dnl check whose result is not used. It does not make the test of dnl GNULIB_UNISTD_H_NONBLOCKING or GNULIB_NONBLOCKING redundant. diff --git a/m4/write.m4 b/m4/write.m4 index fd46acc1b0..2f4a23538e 100644 --- a/m4/write.m4 +++ b/m4/write.m4 @@ -1,4 +1,4 @@ -# write.m4 serial 5 +# write.m4 serial 6 dnl Copyright (C) 2008-2017 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,10 +7,12 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_WRITE], [ AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) - AC_REQUIRE([gl_MSVC_INVAL]) - if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then - REPLACE_WRITE=1 - fi + m4_ifdef([gl_MSVC_INVAL], [ + AC_REQUIRE([gl_MSVC_INVAL]) + if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then + REPLACE_WRITE=1 + fi + ]) dnl This ifdef is just an optimization, to avoid performing a configure dnl check whose result is not used. It does not make the test of dnl GNULIB_UNISTD_H_SIGPIPE or GNULIB_SIGPIPE redundant. diff --git a/modules/msvc-nothrow b/modules/msvc-nothrow index 2e670f9aab..d187eea033 100644 --- a/modules/msvc-nothrow +++ b/modules/msvc-nothrow @@ -15,6 +15,7 @@ AC_REQUIRE([gl_MSVC_NOTHROW]) if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then AC_LIBOBJ([msvc-nothrow]) fi +gl_MODULE_INDICATOR([msvc-nothrow]) Makefile.am: diff --git a/tests/test-cloexec.c b/tests/test-cloexec.c index e30e1302f1..cbfded1252 100644 --- a/tests/test-cloexec.c +++ b/tests/test-cloexec.c @@ -29,7 +29,11 @@ # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "binary-io.h" diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c index a41950a019..936e4847be 100644 --- a/tests/test-dup-safer.c +++ b/tests/test-dup-safer.c @@ -34,7 +34,11 @@ # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #if !O_BINARY diff --git a/tests/test-dup2.c b/tests/test-dup2.c index 8f7df3a195..f98486a810 100644 --- a/tests/test-dup2.c +++ b/tests/test-dup2.c @@ -41,7 +41,11 @@ SIGNATURE_CHECK (dup2, int, (int, int)); # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "macros.h" diff --git a/tests/test-dup3.c b/tests/test-dup3.c index 8b0eef4531..85f32567ce 100644 --- a/tests/test-dup3.c +++ b/tests/test-dup3.c @@ -33,7 +33,11 @@ SIGNATURE_CHECK (dup3, int, (int, int, int)); # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "binary-io.h" diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c index 5df90279d7..a249f9ab01 100644 --- a/tests/test-fcntl.c +++ b/tests/test-fcntl.c @@ -35,7 +35,11 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...)); # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "binary-io.h" diff --git a/tests/test-fgetc.c b/tests/test-fgetc.c index f1a3188903..17edf13759 100644 --- a/tests/test-fgetc.c +++ b/tests/test-fgetc.c @@ -25,7 +25,9 @@ SIGNATURE_CHECK (fgetc, int, (FILE *)); #include #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #include "macros.h" diff --git a/tests/test-fputc.c b/tests/test-fputc.c index dd6993ea9e..448e5f2989 100644 --- a/tests/test-fputc.c +++ b/tests/test-fputc.c @@ -25,7 +25,9 @@ SIGNATURE_CHECK (fputc, int, (int, FILE *)); #include #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #include "macros.h" diff --git a/tests/test-fread.c b/tests/test-fread.c index 1b7c42abec..751774daa6 100644 --- a/tests/test-fread.c +++ b/tests/test-fread.c @@ -25,7 +25,9 @@ SIGNATURE_CHECK (fread, size_t, (void *, size_t, size_t, FILE *)); #include #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #include "macros.h" diff --git a/tests/test-fwrite.c b/tests/test-fwrite.c index f50bbfca39..0dfb15b895 100644 --- a/tests/test-fwrite.c +++ b/tests/test-fwrite.c @@ -25,7 +25,9 @@ SIGNATURE_CHECK (fwrite, size_t, (const void *, size_t, size_t, FILE *)); #include #include -#include "msvc-inval.h" +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +# include "msvc-inval.h" +#endif #include "macros.h" diff --git a/tests/test-pipe.c b/tests/test-pipe.c index d6dc267334..08cfe92e44 100644 --- a/tests/test-pipe.c +++ b/tests/test-pipe.c @@ -29,7 +29,11 @@ SIGNATURE_CHECK (pipe, int, (int[2])); # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "binary-io.h" diff --git a/tests/test-pipe2.c b/tests/test-pipe2.c index 6cebd33e12..b50ea99ba1 100644 --- a/tests/test-pipe2.c +++ b/tests/test-pipe2.c @@ -29,7 +29,11 @@ SIGNATURE_CHECK (pipe2, int, (int[2], int)); # define WIN32_LEAN_AND_MEAN # include /* Get _get_osfhandle. */ -# include "msvc-nothrow.h" +# if GNULIB_MSVC_NOTHROW +# include "msvc-nothrow.h" +# else +# include +# endif #endif #include "binary-io.h" -- 2.39.5