aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-05-29 10:39:06 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-05-29 10:39:06 +0200
commit4b7db4f2ca232c630e334fa56b1eb89848d5fcc5 (patch)
tree55608587f33fc1d6f6a8e40dfdf7fea66c750d7a /libbb
parent171932d7ca62dbb0e0b84a0919e1f3a8a68f03f2 (diff)
downloadbusybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.tar.gz
busybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.tar.bz2
busybox-w32-4b7db4f2ca232c630e334fa56b1eb89848d5fcc5.zip
read_key: drop optimization where we read 3 bytes at once
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c11
-rw-r--r--libbb/read_key.c13
2 files changed, 15 insertions, 9 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index a0b1bcf8e..81f6fdeff 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1451,10 +1451,13 @@ static int lineedit_read_key(char *read_key_buffer)
1451 pfd.events = POLLIN; 1451 pfd.events = POLLIN;
1452 do { 1452 do {
1453 poll_again: 1453 poll_again:
1454 /* Wait for input. Can't just call read_key, it will return 1454 if (read_key_buffer[0] == 0) {
1455 * at once if stdin is in non-blocking mode. */ 1455 /* Wait for input. Can't just call read_key,
1456 safe_poll(&pfd, 1, -1); 1456 * it returns at once if stdin
1457 /* note: read_key sets errno to 0 on success: */ 1457 * is in non-blocking mode. */
1458 safe_poll(&pfd, 1, -1);
1459 }
1460 /* Note: read_key sets errno to 0 on success: */
1458 ic = read_key(STDIN_FILENO, read_key_buffer); 1461 ic = read_key(STDIN_FILENO, read_key_buffer);
1459 if (ENABLE_FEATURE_EDITING_ASK_TERMINAL 1462 if (ENABLE_FEATURE_EDITING_ASK_TERMINAL
1460 && (int32_t)ic == KEYCODE_CURSOR_POS 1463 && (int32_t)ic == KEYCODE_CURSOR_POS
diff --git a/libbb/read_key.c b/libbb/read_key.c
index 3771045d2..6f6c39e45 100644
--- a/libbb/read_key.c
+++ b/libbb/read_key.c
@@ -69,11 +69,14 @@ int64_t FAST_FUNC read_key(int fd, char *buffer)
69 errno = 0; 69 errno = 0;
70 n = (unsigned char) *buffer++; 70 n = (unsigned char) *buffer++;
71 if (n == 0) { 71 if (n == 0) {
72 /* If no data, block waiting for input. If we read more 72 /* If no data, block waiting for input.
73 * than the minimal ESC sequence size, the "n=0" below 73 * It is tempting to read more than one byte here,
74 * would instead have to figure out how much to keep, 74 * but it breaks pasting. Example: at shell prompt,
75 * resulting in larger code. */ 75 * user presses "c","a","t" and then pastes "\nline\n".
76 n = safe_read(fd, buffer, 3); 76 * When we were reading 3 bytes here, we were eating
77 * "li" too, and cat was getting wrong input.
78 */
79 n = safe_read(fd, buffer, 1);
77 if (n <= 0) 80 if (n <= 0)
78 return -1; 81 return -1;
79 } 82 }