diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-01-05 13:06:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 13:06:21 -0500 |
commit | 08ebf8d3a80c65b01d493ca84ad2ab7304a669f9 (patch) | |
tree | 77f73c6e88134d702ca275e43b45f5316ba5b47e /src/nvim/os/fileio.c | |
parent | 39d70fcafd6efa9d01b88bb90cab81c393040453 (diff) | |
parent | 628b717022815a431ea0b980444d6115c644f8c8 (diff) | |
download | rneovim-08ebf8d3a80c65b01d493ca84ad2ab7304a669f9.tar.gz rneovim-08ebf8d3a80c65b01d493ca84ad2ab7304a669f9.tar.bz2 rneovim-08ebf8d3a80c65b01d493ca84ad2ab7304a669f9.zip |
Merge #18706 execute Lua with "nvim -l"
Diffstat (limited to 'src/nvim/os/fileio.c')
-rw-r--r-- | src/nvim/os/fileio.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index bdea82f1ff..e93e1febcb 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -167,6 +167,30 @@ FileDescriptor *file_open_fd_new(int *const error, const int fd, const int flags return fp; } +/// Opens standard input as a FileDescriptor. +FileDescriptor *file_open_stdin(void) + FUNC_ATTR_MALLOC FUNC_ATTR_WARN_UNUSED_RESULT +{ + int error; + int stdin_dup_fd; + if (stdin_fd > 0) { + stdin_dup_fd = stdin_fd; + } else { + stdin_dup_fd = os_dup(STDIN_FILENO); +#ifdef MSWIN + // Replace the original stdin with the console input handle. + os_replace_stdin_to_conin(); +#endif + } + FileDescriptor *const stdin_dup = file_open_fd_new(&error, stdin_dup_fd, + kFileReadOnly|kFileNonBlocking); + assert(stdin_dup != NULL); + if (error != 0) { + ELOG("failed to open stdin: %s", os_strerror(error)); + } + return stdin_dup; +} + /// Close file and free its buffer /// /// @param[in,out] fp File to close. |