diff options
author | erw7 <erw7.github@gmail.com> | 2019-11-16 13:45:37 +0900 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-01-17 11:36:28 +0100 |
commit | 2c8016c7048051da9afd809b580cf8f2d2c69614 (patch) | |
tree | 30020e865a94cd6c3e19ff346a1c16fa5f62cbd3 /src/nvim/os | |
parent | 60c7eabb2feeb95f405deca6680bdd59113edcaa (diff) | |
download | rneovim-2c8016c7048051da9afd809b580cf8f2d2c69614.tar.gz rneovim-2c8016c7048051da9afd809b580cf8f2d2c69614.tar.bz2 rneovim-2c8016c7048051da9afd809b580cf8f2d2c69614.zip |
Add stdin, stdout replacement functions
Diffstat (limited to 'src/nvim/os')
-rw-r--r-- | src/nvim/os/os_win_console.c | 38 | ||||
-rw-r--r-- | src/nvim/os/os_win_console.h | 8 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/nvim/os/os_win_console.c b/src/nvim/os/os_win_console.c new file mode 100644 index 0000000000..50127248a4 --- /dev/null +++ b/src/nvim/os/os_win_console.c @@ -0,0 +1,38 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + +#include "nvim/vim.h" + +int os_get_conin_fd(void) +{ + const HANDLE conin_handle = CreateFile("CONIN$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + assert(conin_handle != INVALID_HANDLE_VALUE); + int conin_fd = _open_osfhandle((intptr_t)conin_handle, _O_RDONLY); + assert(conin_fd != -1); + return conin_fd; +} + +void os_replace_stdin_to_conin(void) +{ + close(STDIN_FILENO); + const int conin_fd = os_get_conin_fd(); + assert(conin_fd == STDIN_FILENO); +} + +void os_replace_stdout_to_conout(void) +{ + close(STDOUT_FILENO); + const HANDLE conout_handle = + CreateFile("CONOUT$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + assert(conout_handle != INVALID_HANDLE_VALUE); + const int conout_fd = _open_osfhandle((intptr_t)conout_handle, 0); + assert(conout_fd == STDOUT_FILENO); +} diff --git a/src/nvim/os/os_win_console.h b/src/nvim/os/os_win_console.h new file mode 100644 index 0000000000..154ec83d8a --- /dev/null +++ b/src/nvim/os/os_win_console.h @@ -0,0 +1,8 @@ +#ifndef NVIM_OS_OS_WIN_CONSOLE_H +#define NVIM_OS_OS_WIN_CONSOLE_H + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "os/os_win_console.h.generated.h" +#endif + +#endif // NVIM_OS_OS_WIN_CONSOLE_H |