From 037576d77b62186551ad07b10eb46a73144b9f84 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 20 Oct 2007 18:30:38 +0000 Subject: read_line_input: fix it to not do any fancy editing if echoing is disabled. ash: make read handling both more correct and smaller read_line_input 4037 4101 +64 input_backward 140 139 -1 readcmd 1079 1070 -9 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/2 up/down: 65/-10) Total: 54 bytes text data bss dec hex filename 777575 1000 9532 788107 c068b busybox_old 777629 1000 9532 788161 c06c1 busybox_unstripped --- libbb/lineedit.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/lineedit.c b/libbb/lineedit.c index c44a228..f65e852 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1259,7 +1259,7 @@ static void win_changed(int nsig) * 0 on ctrl-C, * >0 length of input string, including terminating '\n' */ -int read_line_input(const char* prompt, char* command, int maxsize, line_input_t *st) +int read_line_input(const char *prompt, char *command, int maxsize, line_input_t *st) { int lastWasTab = FALSE; unsigned int ic; @@ -1270,6 +1270,15 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t smalluint prevc; #endif + getTermSettings(0, (void *) &initial_settings); + /* Happens when e.g. stty -echo was run before */ + if (!(initial_settings.c_lflag & ECHO)) { + parse_prompt(prompt); + fflush(stdout); + fgets(command, maxsize, stdin); + return strlen(command); + } + // FIXME: audit & improve this if (maxsize > MAX_LINELEN) maxsize = MAX_LINELEN; @@ -1287,7 +1296,6 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t command_ps = command; command[0] = '\0'; - getTermSettings(0, (void *) &initial_settings); memcpy(&new_settings, &initial_settings, sizeof(new_settings)); new_settings.c_lflag &= ~ICANON; /* unbuffered input */ /* Turn off echoing and CTRL-C, so we can trap it */ -- cgit v1.1