refactor: extract code to open stdin for reading

This commit is contained in:
Justin M. Keyes
2023-01-05 17:39:03 +01:00
parent 7089f33144
commit 628b717022
3 changed files with 26 additions and 27 deletions

View File

@@ -1567,19 +1567,7 @@ static void open_script_files(mparm_T *parmp)
if (parmp->scriptin) {
int error;
if (strequal(parmp->scriptin, "-")) {
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);
FileDescriptor *stdin_dup = file_open_stdin();
scriptin[0] = stdin_dup;
} else {
scriptin[0] = file_open_new(&error, parmp->scriptin,