diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-02 23:24:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 23:24:37 +0200 |
commit | ddf7bb24f98b468d2bc6c16c6f300570fc6530f5 (patch) | |
tree | 8d2c78c2fa94ee7c7bfd40d7cc2f00bc54801eaf /src/nvim/fileio.c | |
parent | a1542b091dd7b919fa8524c1c909ef897dde9299 (diff) | |
parent | ad63b94b03c166f37bda477db6cbac2a9583d586 (diff) | |
download | rneovim-ddf7bb24f98b468d2bc6c16c6f300570fc6530f5.tar.gz rneovim-ddf7bb24f98b468d2bc6c16c6f300570fc6530f5.tar.bz2 rneovim-ddf7bb24f98b468d2bc6c16c6f300570fc6530f5.zip |
Merge pull request #18357 from bfredl/ui_stdin
feat(ui): allow embedder to emulate "cat data | nvim -" behaviour
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r-- | src/nvim/fileio.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 7ca7abccdc..95c373ec5c 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -176,7 +176,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) int readfile(char_u *fname, char_u *sfname, linenr_T from, linenr_T lines_to_skip, linenr_T lines_to_read, exarg_T *eap, int flags, bool silent) { - int fd = 0; + int fd = stdin_fd >= 0 ? stdin_fd : 0; int newfile = (flags & READ_NEW); int check_readonly; int filtering = (flags & READ_FILTER); @@ -1722,17 +1722,19 @@ failed: xfree(buffer); if (read_stdin) { - close(0); + close(fd); + if (stdin_fd < 0) { #ifndef WIN32 - // On Unix, use stderr for stdin, makes shell commands work. - vim_ignored = dup(2); + // On Unix, use stderr for stdin, makes shell commands work. + vim_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); - vim_ignored = _open_osfhandle(conin, _O_RDONLY); + // 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); + vim_ignored = _open_osfhandle(conin, _O_RDONLY); #endif + } } if (tmpname != NULL) { |