diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-18 00:31:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-18 00:36:42 +0100 |
commit | 1e825acf8d715fe49af040cb02f9e96c26955832 (patch) | |
tree | 1ba246aca6ab29b154dd14e61e96fafd6bab475e /libbb | |
parent | 8ad2acf352d790d0bdd792b8e126d58a088451f3 (diff) | |
download | busybox-w32-1e825acf8d715fe49af040cb02f9e96c26955832.tar.gz busybox-w32-1e825acf8d715fe49af040cb02f9e96c26955832.tar.bz2 busybox-w32-1e825acf8d715fe49af040cb02f9e96c26955832.zip |
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.c | 26 | ||||
-rw-r--r-- | libbb/read_key.c | 1 |
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) | |||
2155 | #endif | 2155 | #endif |
2156 | 2156 | ||
2157 | fflush_all(); | 2157 | fflush_all(); |
2158 | while (1) { | 2158 | for (;;) { |
2159 | /* Wait for input. TIMEOUT = -1 makes read_key wait even | 2159 | /* Wait for input. TIMEOUT = -1 makes read_key wait even |
2160 | * on nonblocking stdin, TIMEOUT = 50 makes sure we won't | 2160 | * on nonblocking stdin, TIMEOUT = 50 makes sure we won't |
2161 | * insist on full MB_CUR_MAX buffer to declare input like | 2161 | * 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) | |||
2167 | * | 2167 | * |
2168 | * Note: read_key sets errno to 0 on success. | 2168 | * Note: read_key sets errno to 0 on success. |
2169 | */ | 2169 | */ |
2170 | do { | 2170 | for (;;) { |
2171 | if ((state->flags & LI_INTERRUPTIBLE) && bb_got_signal) { | 2171 | if ((state->flags & LI_INTERRUPTIBLE) && bb_got_signal) { |
2172 | errno = EINTR; | 2172 | errno = EINTR; |
2173 | return -1; | 2173 | return -1; |
2174 | } | 2174 | } |
2175 | //FIXME: still races here with signals, but small window to poll() inside read_key | 2175 | //FIXME: still races here with signals, but small window to poll() inside read_key |
2176 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) | 2176 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) |
2177 | /* errno = 0; - read_key does this itself */ | ||
2177 | ic = read_key(STDIN_FILENO, read_key_buffer, timeout); | 2178 | ic = read_key(STDIN_FILENO, read_key_buffer, timeout); |
2178 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) | 2179 | IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) |
2179 | } while (!(state->flags & LI_INTERRUPTIBLE) && errno == EINTR); | 2180 | if (errno != EINTR) |
2181 | break; | ||
2182 | if (state->flags & LI_INTERRUPTIBLE) { | ||
2183 | /* LI_INTERRUPTIBLE bails out on EINTR, | ||
2184 | * but nothing really guarantees that bb_got_signal | ||
2185 | * is nonzero. Follow the least surprise principle: | ||
2186 | */ | ||
2187 | if (bb_got_signal == 0) | ||
2188 | bb_got_signal = 255; | ||
2189 | goto ret; | ||
2190 | } | ||
2191 | } | ||
2180 | 2192 | ||
2181 | if (errno) { | 2193 | if (errno) { |
2182 | /* LI_INTERRUPTIBLE can bail out with EINTR here, | ||
2183 | * but nothing really guarantees that bb_got_signal | ||
2184 | * is nonzero. Follow the least surprise principle: | ||
2185 | */ | ||
2186 | if (errno == EINTR && bb_got_signal == 0) | ||
2187 | bb_got_signal = 255; /* something nonzero */ | ||
2188 | #if ENABLE_UNICODE_SUPPORT | 2194 | #if ENABLE_UNICODE_SUPPORT |
2189 | if (errno == EAGAIN && unicode_idx != 0) | 2195 | if (errno == EAGAIN && unicode_idx != 0) |
2190 | goto pushback; | 2196 | goto pushback; |
@@ -2251,7 +2257,7 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) | |||
2251 | #endif | 2257 | #endif |
2252 | break; | 2258 | break; |
2253 | } | 2259 | } |
2254 | 2260 | ret: | |
2255 | return ic; | 2261 | return ic; |
2256 | } | 2262 | } |
2257 | 2263 | ||
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) | |||
291 | { | 291 | { |
292 | int64_t r; | 292 | int64_t r; |
293 | do { | 293 | do { |
294 | /* errno = 0; - read_key does this itself */ | ||
294 | r = read_key(fd, buffer, timeout); | 295 | r = read_key(fd, buffer, timeout); |
295 | } while (errno == EINTR); | 296 | } while (errno == EINTR); |
296 | return r; | 297 | return r; |