diff options
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index f76afd3..8262475 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -2155,7 +2155,7 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) #endif fflush_all(); - while (1) { + for (;;) { /* Wait for input. TIMEOUT = -1 makes read_key wait even * on nonblocking stdin, TIMEOUT = 50 makes sure we won't * insist on full MB_CUR_MAX buffer to declare input like @@ -2167,24 +2167,30 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * * Note: read_key sets errno to 0 on success. */ - do { + for (;;) { if ((state->flags & LI_INTERRUPTIBLE) && bb_got_signal) { errno = EINTR; return -1; } //FIXME: still races here with signals, but small window to poll() inside read_key IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) + /* errno = 0; - read_key does this itself */ ic = read_key(STDIN_FILENO, read_key_buffer, timeout); IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) - } while (!(state->flags & LI_INTERRUPTIBLE) && errno == EINTR); + if (errno != EINTR) + break; + if (state->flags & LI_INTERRUPTIBLE) { + /* LI_INTERRUPTIBLE bails out on EINTR, + * but nothing really guarantees that bb_got_signal + * is nonzero. Follow the least surprise principle: + */ + if (bb_got_signal == 0) + bb_got_signal = 255; + goto ret; + } + } if (errno) { - /* LI_INTERRUPTIBLE can bail out with EINTR here, - * but nothing really guarantees that bb_got_signal - * is nonzero. Follow the least surprise principle: - */ - if (errno == EINTR && bb_got_signal == 0) - bb_got_signal = 255; /* something nonzero */ #if ENABLE_UNICODE_SUPPORT if (errno == EAGAIN && unicode_idx != 0) goto pushback; @@ -2251,7 +2257,7 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) #endif break; } - + ret: return ic; } |