diff options
author | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:21:36 -0500 |
---|---|---|
committer | b-r-o-c-k <brockmammen@gmail.com> | 2018-04-14 14:21:36 -0500 |
commit | 387fbcd95cade4b0c037d18f404944676a59db09 (patch) | |
tree | f27c6fecbd40b2edd400ae612c77a30883c30512 | |
parent | ad999eaa775d7d4b0cacedb30c6ea3a0ee699a6f (diff) | |
download | rneovim-387fbcd95cade4b0c037d18f404944676a59db09.tar.gz rneovim-387fbcd95cade4b0c037d18f404944676a59db09.tar.bz2 rneovim-387fbcd95cade4b0c037d18f404944676a59db09.zip |
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.
-rw-r--r-- | src/nvim/main.c | 11 | ||||
-rw-r--r-- | src/nvim/os/fileio.c | 10 | ||||
-rw-r--r-- | test/functional/core/main_spec.lua | 1 |
3 files changed, 16 insertions, 6 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 067184c8c7..4f9a5a979f 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -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); diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index 0ef9307a5a..ccf35fd57c 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -282,6 +282,7 @@ ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf, char *buf = ret_buf; size_t read_remaining = size; RBuffer *const rv = fp->rv; + bool called_read = false; while (read_remaining) { const size_t rv_size = rbuffer_size(rv); if (rv_size > 0) { @@ -289,7 +290,9 @@ ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf, buf += rsize; read_remaining -= rsize; } - if (fp->eof) { + if (fp->eof + // Allow only at most one os_read[v] call. + || (called_read && fp->non_blocking)) { break; } if (read_remaining) { @@ -343,10 +346,7 @@ ptrdiff_t file_read(FileDescriptor *const fp, char *const ret_buf, } } #endif - } - if (fp->non_blocking) { - // Allow only at most one os_read[v] call. - break; + called_read = true; } } return (ptrdiff_t)(size - read_remaining); diff --git a/test/functional/core/main_spec.lua b/test/functional/core/main_spec.lua index 1641149c87..2c4d110f0f 100644 --- a/test/functional/core/main_spec.lua +++ b/test/functional/core/main_spec.lua @@ -36,7 +36,6 @@ describe('Command-line option', function() os.remove(dollar_fname) end) it('treats - as stdin', function() - if helpers.pending_win32(pending) then return end eq(nil, lfs.attributes(fname)) funcs.system( {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless', |