Discussion:
[Emacs-diffs] master 085c7f6 2/2: Test format-time-string with zone arg
(too old to reply)
Paul Eggert
2017-05-02 07:52:03 UTC
Permalink
Raw Message
Eli Zaretskii wrote:

> the utimens.c file you've brought from Gnulib has 2 problems:
>
> . it defines WIN32_LEAN_AND_MEAN unconditionally, which conflicts
> with our own definition in nt/inc/ms-w32.h, which is processed
> earlier;
>
> . it includes msvc-nothrow.h, which is absent in the repository, it
> should have been imported from Gnulib together with utimens.c
>
> I fixed the first of these temporarily, in a way that at least GCC
> lets utimens.c compile, but I think in general utimens.c should do
>
> #ifndef WIN32_LEAN_AND_MEAN
> # define WIN32_LEAN_AND_MEAN
> #endif
>
> to avoid possible clashes with definitions elsewhere in the sources.

I'd like Bruno's opinion on the macro clash, and on the attached patch for the
msvc-nothrow.h issue, a patch that I installed into Gnulib and into Emacs master
to try to get the Emacs master build working again.

For quite some time Emacs has avoided Gnulib's msvc-nothrow and msvc-inval
modules, the reason for which I do not understand (and don't particularly want
to :-). It's trivial to add the msvc-nothrow and msvc-inval machinery to the
Emacs source code, if this is necessary now for some reason: simply remove them
from the AVOIDED_MODULES list in admin/merge-gnulib and then run
admin/merge-gnulib. I don't know whether this would break other parts of the
build on MS-Windows, though.
Eli Zaretskii
2017-05-02 17:09:27 UTC
Permalink
Raw Message
> Cc: ***@cornell.edu, emacs-***@gnu.org, Bruno Haible <***@clisp.org>,
> Gnulib bugs <bug-***@gnu.org>
> From: Paul Eggert <***@cs.ucla.edu>
> Date: Tue, 2 May 2017 00:52:03 -0700
>
> > the utimens.c file you've brought from Gnulib has 2 problems:
> >
> > . it defines WIN32_LEAN_AND_MEAN unconditionally, which conflicts
> > with our own definition in nt/inc/ms-w32.h, which is processed
> > earlier;
> >
> > . it includes msvc-nothrow.h, which is absent in the repository, it
> > should have been imported from Gnulib together with utimens.c
> >
> > I fixed the first of these temporarily, in a way that at least GCC
> > lets utimens.c compile, but I think in general utimens.c should do
> >
> > #ifndef WIN32_LEAN_AND_MEAN
> > # define WIN32_LEAN_AND_MEAN
> > #endif
> >
> > to avoid possible clashes with definitions elsewhere in the sources.
>
> I'd like Bruno's opinion on the macro clash, and on the attached patch for the
> msvc-nothrow.h issue, a patch that I installed into Gnulib and into Emacs master
> to try to get the Emacs master build working again.

Thanks.

> -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
> +/* On native Windows, use SetFileTime; but avoid this when compiling
> + GNU Emacs, which arranges for this in some other way and which
> + defines WIN32_LEAN_AND_MEAN itself. */

That "other way" is the implementation of fdutimens in Emacs's w32.c.
Perhaps Bruno could look at that implementation and comment on its
merits and demerits vs the Gnulib implementation, and we could then
decide whether to start using the Gnulib implementation, augmenting
ours, or something else.
Bruno Haible
2017-05-02 21:55:50 UTC
Permalink
Raw Message
Paul Eggert wrote:
> I'd like Bruno's opinion on the macro clash

The common idiom is "#define WINDOWS_LEAN_AND_MEAN". This can be seen by comparing
the number of hits of two web searches:
https://www.google.de/search?q=%22define+windows_lean_and_mean%22
https://www.google.de/search?q=%22define+windows_lean_and_mean+1%22

> and on the attached patch for the
> msvc-nothrow.h issue, a patch that I installed into Gnulib and into Emacs master

The patch is fine with me: it has no drawbacks for other packages.

However, it would be good to know what qualms you have with the msvc-nothrow
module. Should Emacs be built with mingw, not MSVC? Is an EBADF situation never
going to occur in Emacs anyway? Are the portability efforts for mingw and MSVC
in Gnulib useless for Emacs, because on native Windows Emacs uses its own w32.c
instead anyway? Does Emacs have other requirements I don't know about?

Eli Zaretskii wrote:
> That "other way" is the implementation of fdutimens in Emacs's w32.c.
> Perhaps Bruno could look at that implementation and comment on its
> merits and demerits vs the Gnulib implementation

1) The Emacs w32.c ports to Windows98 as well, whereas Gnulib currently assumes
Windows XP at least (and will soon move to Windows 7, I guess - namely when
no one has a test machine with Windows XP any more). Merit or demerit? Opinion?

2) The Emacs w32.c has an option to use the "W" suffixed Windows APIs by default.
Clearly a merit, because it allows to use file names that are not contained in
the "ANSI codepage". Nowadays users can use (type, display, manipulate) such
file names in the cmd.exe windows; any program which is not on par with this
ability is deficient.
Gnulib still uses the "A" suffixed Windows APIs; clearly a demerit.

3) The Emacs w32.c fdutimens function handles only 1 second resolution; the
Gnulib fdutimens supports sub-second resolution.

4) Different errno mapping:

Filename GetLastError() errno in Emacs errno in Gnulib

'\\server' ERROR_BAD_PATHNAME EINVAL ENOENT
'\\server\nonexistentshare\' ERROR_BAD_NET_NAME EINVAL ENOENT
? ERROR_INVALID_DRIVE ENOENT EINVAL
? ERROR_BAD_NETPATH ENOENT EINVAL
? ERROR_DEV_NOT_EXIST ENOENT EINVAL
'C:\System Volume Information\foo' ERROR_ACCESS_DENIED EACCES EACCESS or EPERM (*)
'C:\pagefile.sys' ERROR_SHARING_VIOLATION EACCES EACCESS or EPERM (*)

(*) According to POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/functions/utime.html

Can you tell me how to provoke a ERROR_INVALID_DRIVE, ERROR_BAD_NETPATH, or
ERROR_DEV_NOT_EXIST error code?

5) Anything else?

Bruno
Paul Eggert
2017-05-02 22:35:03 UTC
Permalink
Raw Message
On 05/02/2017 02:55 PM, Bruno Haible wrote:
> it would be good to know what qualms you have with the msvc-nothrow
> module. Should Emacs be built with mingw, not MSVC? Is an EBADF situation never
> going to occur in Emacs anyway? Are the portability efforts for mingw and MSVC
> in Gnulib useless for Emacs, because on native Windows Emacs uses its own w32.c
> instead anyway? Does Emacs have other requirements I don't know about?

I know little about MS-Windows. Emacs has gotten along without
msvc-nothrow and msvc-inval for quite some time and so may not need
them. Adding them to Emacs may break MS-Windows builds in subtle ways
that I am not qualified to judge. So, being cautious, I omitted them.

There was a similar issue with the recent Gnulib changes for
daylight-saving time in MS-Windows, where I omitted the relevant modules
from Emacs because Emacs has been running for years without these DST
fixes and I worried that adding the new Gnulib modules would break
and/or complicate the Emacs build unnecessarily.

It should be easy enough for someone with MS-Windows expertise to
experiment with the new Gnulib functionality in Emacs: in the Emacs
master branch, edit admin/merge-gnulib's AVOIDED_MODULES variable so
that it no longer lists the modules you want to use. Then run
admin/merge-gnulib and build the result on MS-Windows.

> 1) The Emacs w32.c ports to Windows98 as well, whereas Gnulib currently assumes
> Windows XP at least (and will soon move to Windows 7, I guess - namely when
> no one has a test machine with Windows XP any more). Merit or demerit? Opinion?

In the past Eli has argued for supporting ancient MS-Windows and MS-DOS
versions. I don't know whether he still cares. (By "ancient" I mean that
Microsoft itself no longer supports them.)
Eli Zaretskii
2017-05-03 15:49:40 UTC
Permalink
Raw Message
> Cc: ***@cornell.edu, emacs-***@gnu.org, bug-***@gnu.org
> From: Paul Eggert <***@cs.ucla.edu>
> Date: Tue, 2 May 2017 15:35:03 -0700
>
> > 1) The Emacs w32.c ports to Windows98 as well, whereas Gnulib currently assumes
> > Windows XP at least (and will soon move to Windows 7, I guess - namely when
> > no one has a test machine with Windows XP any more). Merit or demerit? Opinion?
>
> In the past Eli has argued for supporting ancient MS-Windows and MS-DOS
> versions. I don't know whether he still cares. (By "ancient" I mean that
> Microsoft itself no longer supports them.)

We still try to support Windows 9X, but MS-DOS is not relevant to this
discussion, as it does use the Gnulib implementation of fdutimens.
Eli Zaretskii
2017-05-03 15:33:11 UTC
Permalink
Raw Message
> From: Bruno Haible <***@clisp.org>
> Cc: ***@cornell.edu, emacs-***@gnu.org, bug-***@gnu.org
> Date: Tue, 02 May 2017 23:55:50 +0200
>
> The patch is fine with me: it has no drawbacks for other packages.

Thanks.

> However, it would be good to know what qualms you have with the msvc-nothrow
> module. Should Emacs be built with mingw, not MSVC?

Emacs dropped MSVC support a few years ago. Only MinGW, with its 2
flavors, is currently supported, in addition to Cygwin. Emacs might
still build with MSVC, but I don't think anyone tried in a long while,
and if they do, they will be in for a ride, because we require the
MSYS tools to run the configure script and the Makefiles.

> Is an EBADF situation never going to occur in Emacs anyway?

It can occur, but AFAIK it cannot cause an exception, since the only
supported runtime is msvcrt.dll.

> Are the portability efforts for mingw and MSVC
> in Gnulib useless for Emacs, because on native Windows Emacs uses its own w32.c
> instead anyway?

Many features available from Gnulib are indeed independently
implemented in w32.c and other Windows-specific files in Emacs. The
reasons vary -- some are of historical nature, others because the
Emacs implementations are "better" in some sense. The support for
non-ASCII file names outside of the current system codepage is a good
example of the latter.

> Does Emacs have other requirements I don't know about?

Some. For example, Emacs cannot use the C runtime functions that
manipulate non-ASCII characters, because those are limited to the BMP
on Windows, and don't support UTF-8.

> Eli Zaretskii wrote:
> > That "other way" is the implementation of fdutimens in Emacs's w32.c.
> > Perhaps Bruno could look at that implementation and comment on its
> > merits and demerits vs the Gnulib implementation
>
> 1) The Emacs w32.c ports to Windows98 as well, whereas Gnulib currently assumes
> Windows XP at least (and will soon move to Windows 7, I guess - namely when
> no one has a test machine with Windows XP any more). Merit or demerit? Opinion?

Emacs still tries to support Windows 9X and the NT family members
older than XP, yes. But AFAICT, the APIs used in the Gnulib
implementation of fdutimens are all supported on Windows 9X.

> 2) The Emacs w32.c has an option to use the "W" suffixed Windows APIs by default.
> Clearly a merit, because it allows to use file names that are not contained in
> the "ANSI codepage". Nowadays users can use (type, display, manipulate) such
> file names in the cmd.exe windows; any program which is not on par with this
> ability is deficient.

In a GUI session, Emacs supports all the Unicode characters, so
limiting file names to the current codepage makes even less sense than
for console programs running in the cmd window.

> 3) The Emacs w32.c fdutimens function handles only 1 second resolution; the
> Gnulib fdutimens supports sub-second resolution.

I guess we should plan on reimplementing the Emacs version using the
more flexible Win32 APIs, to support sub-second resolution.

> Can you tell me how to provoke a ERROR_INVALID_DRIVE, ERROR_BAD_NETPATH, or
> ERROR_DEV_NOT_EXIST error code?

I don't remember. It's entirely possible that I just looked at the
textual representation of these errors and matched the errno values
without actually creating the situation.

Thanks for the detailed analysis.
Bruno Haible
2017-05-09 20:17:58 UTC
Permalink
Raw Message
Hi Eli and Paul,

I'm trying to understand whether the #ifs you are adding for Emacs could
be generalized for gnulib users other than Emacs.

On one hand, Eli writes:
> Emacs dropped MSVC support a few years ago. Only MinGW, with its 2
> flavors, is currently supported, in addition to Cygwin.

On the other hand, Paul commits patches that disable mingw AND MSVC support,
presumably for functions that are implemented in Emacs' w32.c.

Would a gnulib-wide option "ignore mingw and MSVC portability" be useful for
Emacs? Is it something that we should offer as a documented feature?

Would a gnulib-wide option "ignore MSVC portability" be useful for Emacs?
Is it something that we should offer as a documented feature?
(I would see it as quite arbitrary: it is like supporting GCC but not SUNWspro
cc on Solaris.)

If the answer to both questions is "no", then OK, the best approach then is to
continue with "#ifndef EMACS_CONFIGURATION" here and there.

Bruno
Paul Eggert
2017-05-09 21:08:19 UTC
Permalink
Raw Message
On 05/09/2017 01:17 PM, Bruno Haible wrote:
> Hi Eli and Paul,
>
> I'm trying to understand whether the #ifs you are adding for Emacs could
> be generalized for gnulib users other than Emacs.
>
> On one hand, Eli writes:
>> Emacs dropped MSVC support a few years ago. Only MinGW, with its 2
>> flavors, is currently supported, in addition to Cygwin.
> On the other hand, Paul commits patches that disable mingw AND MSVC support,
> presumably for functions that are implemented in Emacs' w32.c.

Yes, the idea there is to avoid having Emacs have two sets of C source
code to support the same low-level function, as this complicates
maintenance (and could lead to bugs).

I suppose it'd be nicer if Emacs could use the Gnulib versions of the
code instead of having its own version, as that would help Emacs and
other GNU programs share solutions better; but this would require some
hacking and it's not clear it's worth the effort (which I wouldn't be
able to do, myself).

> Would a gnulib-wide option "ignore mingw and MSVC portability" be useful for
> Emacs? Is it something that we should offer as a documented feature?

It could be a little tricky to define exactly what we mean by "ignore
mingw portability". Aside from the EMACS_CONFIGURATION hack in
gnulib/lib/utimens.c, gnulib/lib/time.in.h looks at __MINGW32__;
presumably the latter should be retained for Emacs even if Emacs uses
the gnulib-tool option you're thinking of. These are the only two
collisions I know of right now.

> Would a gnulib-wide option "ignore MSVC portability" be useful for Emacs?
> Is it something that we should offer as a documented feature?
> (I would see it as quite arbitrary: it is like supporting GCC but not SUNWspro
> cc on Solaris.)
>
> If the answer to both questions is "no", then OK, the best approach then is to
> continue with "#ifndef EMACS_CONFIGURATION" here and there.
>

I hope we don't need to put "#ifdef EMACS_CONFIGURATION" in a lot of
places in Gnulib. Currently it's present in only one place, which is
something we can tolerate. But a dozen places would indicate that we
need a better solution, perhaps along the lines you're suggesting.
Eli Zaretskii
2017-05-10 02:39:50 UTC
Permalink
Raw Message
> From: Paul Eggert <***@cs.ucla.edu>
> Date: Tue, 9 May 2017 14:08:19 -0700
>
> I suppose it'd be nicer if Emacs could use the Gnulib versions of the
> code instead of having its own version, as that would help Emacs and
> other GNU programs share solutions better; but this would require some
> hacking and it's not clear it's worth the effort (which I wouldn't be
> able to do, myself).

As explained elsewhere, Emacs cannot rely on Gnulib completely, due to
some features Gnulib doesn't support, like file names which cannot be
expressed within the current system codepage's character set. Another
class of issues that prevent full Gnulib acceptance is the support for
'select' on non-socket handles, which in Emacs goes together with
support for async subprocesses and SIGCHLD emulation.

> I hope we don't need to put "#ifdef EMACS_CONFIGURATION" in a lot of
> places in Gnulib.

I don't expect that to be in a lot of places, because we generally
disable incorporation of Gnulib modules in the MinGW build on the
module level.
Eli Zaretskii
2017-05-10 02:34:49 UTC
Permalink
Raw Message
> From: Bruno Haible <***@clisp.org>
> Date: Tue, 09 May 2017 22:17:58 +0200
>
> Would a gnulib-wide option "ignore mingw and MSVC portability" be useful for
> Emacs?

Not as a global option, because the MinGW port of Emacs does use some
Gnulib functions.

> Would a gnulib-wide option "ignore MSVC portability" be useful for Emacs?

Yes, most probably, because Emacs no longer supports MSVC builds
(although you might still find traces of that in the sources).
Bruno Haible
2017-05-10 21:27:46 UTC
Permalink
Raw Message
Eli Zaretskii wrote:
> > Would a gnulib-wide option "ignore MSVC portability" be useful for Emacs?
>
> Yes, most probably, because Emacs no longer supports MSVC builds
> (although you might still find traces of that in the sources).

OK, so I'm documenting that the existing practice of Emacs (namely,
--avoid=msvc-inval --avoid=msvc-nothrow) works for this purpose, and
make it work throughout gnulib.


2017-05-10 Bruno Haible <***@clisp.org>

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.

diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 378cee6..d23ab9c 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 0000000..781612b
--- /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 040fb9f..997f75a 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 3e45187..6a72c32 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 819e9e3..69887b0 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 c0c7cad..002dc8c 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 ed9b37a..418d1ab 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 facff2b..fc6f608 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 afe1546..d4dd144 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 7698e43..0c55d52 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 a4896e3..605ac7d 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 d7de6d8..846f308 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 913df19..f0ecae2 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 7fabb51..c356cf4 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 a28a3ae..f142558 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 dbc63b5..535ece9 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 f050426..dba4380 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 e603539..9c991a3 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 300ed41..86a8808 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 3d031aa..b9ed86a 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 078b1ba..9115bcd 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 d3325a6..0a6d8ca 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 08108f7..a9b943f 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 ac86c49..01b1982 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 9333ee4..028e20e 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 8392e57..23ad74d 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 8caf2f0..98db749 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 8ad693b..34b22f5 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 b4bfa8e..ff4eab0 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 8ac8ab7..2f753fb 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 7932662..26ff658 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 6a3b623..b81db62 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

diff --git a/m4/close.m4 b/m4/close.m4
index 005a43a..ed357ab 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 74fa9bd..75307cb 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 8e8619c..42f928e 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 28c2e0b..fe6e068 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 36249ab..2466802 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 fd46acc..2f4a235 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 2e670f9..d187eea 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 e30e130..cbfded1 100644
--- a/tests/test-cloexec.c
+++ b/tests/test-cloexec.c
@@ -29,7 +29,11 @@
# 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

#include "binary-io.h"
diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c
index a41950a..936e484 100644
--- a/tests/test-dup-safer.c
+++ b/tests/test-dup-safer.c
@@ -34,7 +34,11 @@
# 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

#if !O_BINARY
diff --git a/tests/test-dup2.c b/tests/test-dup2.c
index 8f7df3a..f98486a 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#endif

#include "macros.h"
diff --git a/tests/test-dup3.c b/tests/test-dup3.c
index 8b0eef4..85f3256 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#endif

#include "binary-io.h"
diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c
index 5df9027..a249f9a 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#endif

#include "binary-io.h"
diff --git a/tests/test-fgetc.c b/tests/test-fgetc.c
index f1a3188..17edf13 100644
--- a/tests/test-fgetc.c
+++ b/tests/test-fgetc.c
@@ -25,7 +25,9 @@ SIGNATURE_CHECK (fgetc, int, (FILE *));
#include <fcntl.h>
#include <unistd.h>

-#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 dd6993e..448e5f2 100644
--- a/tests/test-fputc.c
+++ b/tests/test-fputc.c
@@ -25,7 +25,9 @@ SIGNATURE_CHECK (fputc, int, (int, FILE *));
#include <fcntl.h>
#include <unistd.h>

-#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 1b7c42a..751774d 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 <fcntl.h>
#include <unistd.h>

-#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 f50bbfc..0dfb15b 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 <fcntl.h>
#include <unistd.h>

-#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 d6dc267..08cfe92 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#endif

#include "binary-io.h"
diff --git a/tests/test-pipe2.c b/tests/test-pipe2.c
index 6cebd33..b50ea99 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 <windows.h>
/* Get _get_osfhandle. */
-# include "msvc-nothrow.h"
+# if GNULIB_MSVC_NOTHROW
+# include "msvc-nothrow.h"
+# else
+# include <io.h>
+# endif
#endif

#include "binary-io.h"
Davis Herring
2017-05-03 19:33:55 UTC
Permalink
Raw Message
On 05/02/2017 03:55 PM, Bruno Haible wrote:
> Filename GetLastError() errno in Emacs errno in Gnulib
>
> '\\server' ERROR_BAD_PATHNAME EINVAL ENOENT
> '\\server\nonexistentshare\' ERROR_BAD_NET_NAME EINVAL ENOENT
> ? ERROR_INVALID_DRIVE ENOENT EINVAL
> ? ERROR_BAD_NETPATH ENOENT EINVAL
> ? ERROR_DEV_NOT_EXIST ENOENT EINVAL
> 'C:\System Volume Information\foo' ERROR_ACCESS_DENIED EACCES EACCESS or EPERM (*)
> 'C:\pagefile.sys' ERROR_SHARING_VIOLATION EACCES EACCESS or EPERM (*)
>
> (*) According to POSIX: http://pubs.opengroup.org/onlinepubs/9699919799/functions/utime.html
>
> Can you tell me how to provoke a ERROR_INVALID_DRIVE, ERROR_BAD_NETPATH, or
> ERROR_DEV_NOT_EXIST error code?

Billy O'Neal (copied) at Microsoft might be able to help; he's been
doing similar error-code mapping for their filesystems (for C++17).

Davis

--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
Billy O'Neal (VC LIBS)
2017-05-03 21:12:33 UTC
Permalink
Raw Message
I’m not an expert at all in this area. I did run a few queries against Win sources though.

I think ERROR_INVALID_DRIVE is dead. The only place I found it mentioned was in the CRT trying to translate it to ENOENT. There was a comment from 1989 there, it may have meant something in the DOS / Win9x days.

ERROR_BAD_NETPATH seems to happen when the path looks okay but DNS fails on the input:

//
// MessageId: ERROR_BAD_NETPATH
//
// MessageText:
//
// The network path was not found.
//
#define ERROR_BAD_NETPATH 53L

C:\Users\bion\Desktop>type test_error.cpp
#include <stdio.h>
#include <system_error>
#include <Windows.h>

int wmain(int argc, wchar_t *argv[]) {
if (argc != 2) {
puts("usage: test_error.exe path");
return -1;
}
HANDLE hFile = CreateFileW(
argv[1],
FILE_READ_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
nullptr);

if (hFile != INVALID_HANDLE_VALUE) {
puts("didn't get expected error");
CloseHandle(hFile);
return -1;
}

DWORD lastError = GetLastError();
printf("GetLastError() == %lu == 0x%08lX: %s", lastError, lastError,
std::system_category().message(lastError).c_str());
return 0;
}

C:\Users\bion\Desktop>cl /nologo /EHsc /W4 /WX .\test_error.cpp
test_error.cpp

C:\Users\bion\Desktop>.\test_error.exe \\notaserver.example.com\foo\bar\baz
GetLastError() == 53 == 0x00000035: The network path was not found.

C:\Users\bion\Desktop>

I don’t think ERROR_DEV_NOT_EXIST can be triggered from a file path. I saw it only in places where mount points were being processed. (e.g. you tried to mount this device but that device doesn’t exist) But I’m not positive.

Hope that helps,

Billy3

From: Davis Herring<mailto:***@lanl.gov>
Sent: Wednesday, May 3, 2017 12:36 PM
To: Bruno Haible<mailto:***@clisp.org>; Eli Zaretskii<mailto:***@gnu.org>; Paul Eggert<mailto:***@cs.ucla.edu>
Cc: bug-***@gnu.org<mailto:bug-***@gnu.org>; ***@cornell.edu<mailto:***@cornell.edu>; emacs-***@gnu.org<mailto:emacs-***@gnu.org>; Billy O'Neal (VC LIBS)<mailto:***@microsoft.com>
Subject: Re: [Emacs-diffs] master 085c7f6 2/2: Test format-time-string with zone arg

On 05/02/2017 03:55 PM, Bruno Haible wrote:
> Filename GetLastError() errno in Emacs errno in Gnulib
>
> '\\server' ERROR_BAD_PATHNAME EINVAL ENOENT
> '\\server\nonexistentshare\<file://server/nonexistentshare/>' ERROR_BAD_NET_NAME EINVAL ENOENT
> ? ERROR_INVALID_DRIVE ENOENT EINVAL
> ? ERROR_BAD_NETPATH ENOENT EINVAL
> ? ERROR_DEV_NOT_EXIST ENOENT EINVAL
> 'C:\System Volume Information\foo' ERROR_ACCESS_DENIED EACCES EACCESS or EPERM (*)
> 'C:\pagefile.sys' ERROR_SHARING_VIOLATION EACCES EACCESS or EPERM (*)
>
> (*) According to POSIX: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpubs.opengroup.org%2Fonlinepubs%2F9699919799%2Ffunctions%2Futime.html&data=02%7C01%7Cbion%40microsoft.com%7C60b0e84189a14768804d08d4925ba869%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636294369742721148&sdata=s77csbmK5uw8tn7mB6JvCYJ%2BlMQFB9FDtCrgi01z5EE%3D&reserved=0
>
> Can you tell me how to provoke a ERROR_INVALID_DRIVE, ERROR_BAD_NETPATH, or
> ERROR_DEV_NOT_EXIST error code?

Billy O'Neal (copied) at Microsoft might be able to help; he's been
doing similar error-code mapping for their filesystems (for C++17).

Davis

--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
Eli Zaretskii
2017-05-04 14:26:19 UTC
Permalink
Raw Message
> From: "Billy O'Neal (VC LIBS)" <***@microsoft.com>
> CC: "bug-***@gnu.org" <bug-***@gnu.org>, "***@cornell.edu"
> <***@cornell.edu>, "emacs-***@gnu.org" <emacs-***@gnu.org>
> Date: Wed, 3 May 2017 21:12:33 +0000
>
> I’m not an expert at all in this area. I did run a few queries against Win sources though.

Thanks for your input, much appreciated.
Bruno Haible
2017-05-07 21:47:21 UTC
Permalink
Raw Message
Billy O'Neal wrote:
> I think ERROR_INVALID_DRIVE is dead.
> ...
> ERROR_BAD_NETPATH seems to happen when the path looks okay but DNS fails on the input:
> ...
> I don’t think ERROR_DEV_NOT_EXIST can be triggered from a file path.

Thanks a lot for these infos! I'm updating the error mapping in gnulib:


2017-05-07 Bruno Haible <***@clisp.org>

utime: Handle more Windows error codes.
* lib/utime.c (utime): Handle ERROR_BAD_NETPATH.
Based on explanations by Billy O'Neal.

diff --git a/lib/utime.c b/lib/utime.c
index ac5c78b..230d36b 100644
--- a/lib/utime.c
+++ b/lib/utime.c
@@ -193,6 +193,7 @@ utime (const char *name, const struct utimbuf *ts)
case ERROR_FILE_NOT_FOUND: /* The last component of rname does not exist. */
case ERROR_PATH_NOT_FOUND: /* Some directory component in rname does not exist. */
case ERROR_BAD_PATHNAME: /* rname is such as '\\server'. */
+ case ERROR_BAD_NETPATH: /* rname is such as '\\nonexistentserver\share'. */
case ERROR_BAD_NET_NAME: /* rname is such as '\\server\nonexistentshare'. */
case ERROR_INVALID_NAME: /* rname contains wildcards, misplaced colon, etc. */
case ERROR_DIRECTORY:
@@ -201,7 +202,6 @@ utime (const char *name, const struct utimbuf *ts)

case ERROR_ACCESS_DENIED: /* rname is such as 'C:\System Volume Information\foo'. */
case ERROR_SHARING_VIOLATION: /* rname is such as 'C:\pagefile.sys'. */
- /* XXX map to EACCESS or EPERM? */
errno = (ts != NULL ? EPERM : EACCES);
break;
Loading...