shell_builtin_read: set cc[VMIN] to 1; lineedit: don't clear c_cc[VINTR]

First change fixes "read -n NUM". Apparently poll() won't report
data availability if cc[VMIN] > 1 until there are at least cc[VMIN] bytes.

function                                             old     new   delta
read_line_input                                     3885    3877      -8
shell_builtin_read                                  1097    1087     -10
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2012-01-15 22:58:06 +01:00
parent d29ae7e071
commit 7ce209b9d4
2 changed files with 16 additions and 7 deletions

View File

@ -138,7 +138,13 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
old_tty = tty;
if (nchars) {
tty.c_lflag &= ~ICANON;
tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
// Setting it to more than 1 breaks poll():
// it blocks even if there's data. !??
//tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
/* reads would block only if < 1 char is available */
tty.c_cc[VMIN] = 1;
/* no timeout (reads block forever) */
tty.c_cc[VTIME] = 0;
}
if (read_flags & BUILTIN_READ_SILENT) {
tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);