win: Fix reading from stdin

* Reading from stdin on Windows is fixed in the same way as it was in
  #8267.
* The file_read function was returning without filling the
  destination buffer when it was called with a non-blocking file
  descriptor.
This commit is contained in:
b-r-o-c-k
2018-04-14 14:21:36 -05:00
parent ad999eaa77
commit 387fbcd95c
3 changed files with 16 additions and 6 deletions

View File

@@ -1096,6 +1096,17 @@ scripterror:
int error;
if (STRCMP(argv[0], "-") == 0) {
const int stdin_dup_fd = os_dup(STDIN_FILENO);
#ifdef WIN32
// On Windows, replace the original stdin with the
// console input handle.
close(STDIN_FILENO);
const HANDLE conin_handle =
CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING, 0, (HANDLE)NULL);
const int conin_fd = _open_osfhandle(conin_handle, _O_RDONLY);
assert(conin_fd == STDIN_FILENO);
#endif
FileDescriptor *const stdin_dup = file_open_fd_new(
&error, stdin_dup_fd, kFileReadOnly|kFileNonBlocking);
assert(stdin_dup != NULL);