summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2022-01-18 00:31:27 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2022-01-18 00:36:42 +0100
commit1e825acf8d715fe49af040cb02f9e96c26955832 (patch)
tree1ba246aca6ab29b154dd14e61e96fafd6bab475e /libbb
parent8ad2acf352d790d0bdd792b8e126d58a088451f3 (diff)
downloadbusybox-1e825acf8d715fe49af040cb02f9e96c26955832.tar.gz
libbb: shrink lineedit_read_key()
function old new delta lineedit_read_key 237 231 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c26
-rw-r--r--libbb/read_key.c1
2 files changed, 17 insertions, 10 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index f76afd37d..82624757e 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;
}
diff --git a/libbb/read_key.c b/libbb/read_key.c
index 829ae215c..cf8ed411e 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -291,6 +291,7 @@ int64_t FAST_FUNC safe_read_key(int fd, char *buffer, int timeout)
{
int64_t r;
do {
+ /* errno = 0; - read_key does this itself */
r = read_key(fd, buffer, timeout);
} while (errno == EINTR);
return r;