summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2017-05-10 21:52:21 +0200
committerBruno Haible <bruno@clisp.org>2017-05-10 22:18:34 +0200
commit03c3f38b55d6654263f924f35145cbb9add4e77d (patch)
treecfafb557985a48a5028cc07bbc95858e648de4fd /lib
parent1888a27a1e48e4f8b9006c164ba1d1218a143c28 (diff)
downloadgnulib-03c3f38b55d6654263f924f35145cbb9add4e77d.tar.gz
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 <io.h> 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 <io.h> 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.
Diffstat (limited to 'lib')
-rw-r--r--lib/accept4.c6
-rw-r--r--lib/close.c4
-rw-r--r--lib/dup.c4
-rw-r--r--lib/dup2.c44
-rw-r--r--lib/error.c6
-rw-r--r--lib/fclose.c4
-rw-r--r--lib/fcntl.c6
-rw-r--r--lib/flock.c6
-rw-r--r--lib/fstat.c6
-rw-r--r--lib/fsync.c6
-rw-r--r--lib/ftruncate.c11
-rw-r--r--lib/getdtablesize.c11
-rw-r--r--lib/ioctl.c6
-rw-r--r--lib/isapipe.c6
-rw-r--r--lib/isatty.c10
-rw-r--r--lib/lseek.c6
-rw-r--r--lib/msvc-nothrow.c4
-rw-r--r--lib/nonblocking.c6
-rw-r--r--lib/poll.c6
-rw-r--r--lib/raise.c4
-rw-r--r--lib/read.c10
-rw-r--r--lib/select.c6
-rw-r--r--lib/sockets.c6
-rw-r--r--lib/sockets.h12
-rw-r--r--lib/stdio-read.c6
-rw-r--r--lib/stdio-write.c6
-rw-r--r--lib/utimens.c6
-rw-r--r--lib/w32sock.h6
-rw-r--r--lib/w32spawn.h6
-rw-r--r--lib/write.c10
30 files changed, 184 insertions, 52 deletions
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 <errno.h>
#include <fcntl.h>
#include "binary-io.h"
-#include "msvc-nothrow.h"
+#if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+#else
+# include <io.h>
+#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 <errno.h>
#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 <errno.h>
-#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 <windows.h>
-# 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 <io.h>
+# 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <unistd.h>
#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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <errno.h>
/* _get_osfhandle */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <errno.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <stdio.h>
-# 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 <io.h>
+# 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-#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 <io.h>
+#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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#else
# include <sys/stat.h>
#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 <windows.h>
-#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 <windows.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <io.h>
# include <stdio.h>
# include <conio.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#else
# include <sys/time.h>
# include <unistd.h>
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 <errno.h>
-# 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 <windows.h>
-# 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 <io.h>
+# 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 <sys/time.h>
-#include "msvc-nothrow.h"
+#if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+#else
+# include <io.h>
+#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 <sys/socket.h>
# include "fd-hook.h"
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <sys/socket.h>
+# include <sys/socket.h>
-#include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <io.h>
/* Get _get_osfhandle(). */
-#include "msvc-nothrow.h"
+#if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+#else
+# include <io.h>
+#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 <errno.h>
/* Get _get_osfhandle(). */
-#include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# 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 <windows.h>
-# 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 <io.h>
+# endif
# undef write