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] e7499ddc33/src/fileio.c (L2397-L2398)
[2] e7499ddc33/src/os_win32.c (L1703-L1714)
This commit is contained in:
b-r-o-c-k 2018-04-14 14:59:07 -05:00 committed by Justin M. Keyes
parent ef4feab0e7
commit ee4e1fd8ec
1 changed files with 9 additions and 1 deletions

View File

@ -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) {