diff options
author | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:59:07 -0500 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-04-14 21:59:07 +0200 |
commit | ee4e1fd8ecf1747b55d2968084047552429cedee (patch) | |
tree | 0090701e9b5168472fcceaca807b1b08ddea26ec /src/nvim/fileio.c | |
parent | ef4feab0e75be19c5f41d70a001db980b72090f5 (diff) | |
download | rneovim-ee4e1fd8ecf1747b55d2968084047552429cedee.tar.gz rneovim-ee4e1fd8ecf1747b55d2968084047552429cedee.tar.bz2 rneovim-ee4e1fd8ecf1747b55d2968084047552429cedee.zip |
win: Fix reading content from stdin (#8267)
Fixes #6890 by reading from the Windows console input buffer after
stdin has been closed.
Vim defines HAVE_DUP for Windows and does the close-dup dance[1]:
close(0);
dup(2);
which always fails, then falls back to reading from the Windows console
input buffer[2].
[1] https://github.com/vim/vim/blob/e7499ddc33508d3d341e96f84a0e7b95b2d6927c/src/fileio.c#L2397-L2398
[2] https://github.com/vim/vim/blob/e7499ddc33508d3d341e96f84a0e7b95b2d6927c/src/os_win32.c#L1703-L1714
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 25653deb3e..4adff63b95 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1737,9 +1737,17 @@ failed: xfree(buffer); if (read_stdin) { - /* Use stderr for stdin, makes shell commands work. */ close(0); +#ifndef WIN32 + // On Unix, use stderr for stdin, makes shell commands work. ignored = dup(2); +#else + // On Windows, use the console input handle for stdin. + HANDLE conin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + ignored = _open_osfhandle(conin, _O_RDONLY); +#endif } if (tmpname != NULL) { |