diff --git a/gdb/utils.c b/gdb/utils.c index 57f267a..175b2fc 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -67,6 +67,8 @@ #include #include +#include "gdb_usleep.h" + #if !HAVE_DECL_MALLOC extern PTR malloc (); /* OK: PTR */ #endif @@ -1477,6 +1479,20 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) gdb_flush (gdb_stdout); answer = fgetc (stdin); + + /* On terminals opened with the NONBLOCK flag, fgetc can return EOF + when there is nothing to read. To distinguish this case from + a true EOF, we need to check the file error condition and see + if fgetc might have set errno to EAGAIN. */ + while (answer == EOF && ferror (stdin) && errno == EAGAIN) + { + /* Not a real EOF. Wait a little while and try again until + we read something. */ + clearerr (stdin); + gdb_usleep (10000); + answer = fgetc (stdin); + } + clearerr (stdin); /* in case of C-d */ if (answer == EOF) /* C-d */ {