Commit f0d36855 authored by Lion Yang's avatar Lion Yang Committed by Benno Schulenberg
Browse files

input: ensure that standard input uses blocking mode


The function get_key_buffer() assumes waiting_mode = TRUE, but stdin
can be in non-blocking mode when a program (before nano) turned stdin
to non-blocking mode and did not change it back (possibly because it
crashed).  So, explicitly set stdin to blocking mode at startup.
Signed-off-by: default avatarLion Yang <lion@aosc.io>
No related merge requests found
Showing with 6 additions and 1 deletion
+6 -1
......@@ -1887,7 +1887,7 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
int main(int argc, char **argv)
{
int optchr;
int stdin_flags, optchr;
#if defined(ENABLED_WRAPORJUSTIFY) && defined(ENABLE_NANORC)
bool fill_used = FALSE;
/* Was the fill option used on the command line? */
......@@ -1978,6 +1978,11 @@ int main(int argc, char **argv)
/* Back up the terminal settings so that they can be restored. */
tcgetattr(0, &oldterm);
/* Get the state of standard input and ensure it uses blocking mode. */
stdin_flags = fcntl(0, F_GETFL, 0);
if (stdin_flags != -1)
fcntl(0, F_SETFL, stdin_flags & ~O_NONBLOCK);
#ifdef ENABLE_UTF8
/* If setting the locale is successful and it uses UTF-8, we need
* to use the multibyte functions for text processing. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment