From d6efa2a9775790b8662393a9f9634516b647e091 Mon Sep 17 00:00:00 2001 From: Jim Ingham Date: Thu, 27 Feb 2014 19:48:13 +0000 Subject: [PATCH] Check call to fgetc for EINTR. llvm-svn: 202426 --- lldb/source/Host/common/Editline.cpp | 51 +++++++++++++++++----------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/lldb/source/Host/common/Editline.cpp b/lldb/source/Host/common/Editline.cpp index 679aadd54c4f..9f96ce15f000 100644 --- a/lldb/source/Host/common/Editline.cpp +++ b/lldb/source/Host/common/Editline.cpp @@ -640,29 +640,40 @@ Editline::GetCharFromInputFileCallback (EditLine *e, char *c) Editline *editline = GetClientData (e); if (editline && editline->m_got_eof == false) { - char ch = ::fgetc(editline->GetInputFile()); - if (ch == '\x04') + while (1) { - // Only turn a CTRL+D into a EOF if we receive the - // CTRL+D an empty line, otherwise it will forward - // delete the character at the cursor - const LineInfo *line_info = ::el_line(e); - if (line_info != NULL && - line_info->buffer == line_info->cursor && - line_info->cursor == line_info->lastchar) + errno = 0; + char ch = ::fgetc(editline->GetInputFile()); + if (ch == '\x04') { - ch = EOF; + // Only turn a CTRL+D into a EOF if we receive the + // CTRL+D an empty line, otherwise it will forward + // delete the character at the cursor + const LineInfo *line_info = ::el_line(e); + if (line_info != NULL && + line_info->buffer == line_info->cursor && + line_info->cursor == line_info->lastchar) + { + ch = EOF; + errno = 0; + } + } + + if (ch == EOF) + { + if (errno == EINTR) + continue; + else + { + editline->m_got_eof = true; + break; + } + } + else + { + *c = ch; + return 1; } - } - - if (ch == EOF) - { - editline->m_got_eof = true; - } - else - { - *c = ch; - return 1; } } return 0; -- GitLab