summaryrefslogtreecommitdiff
path: root/shell/shell_common.c
diff options
context:
space:
mode:
authorDenys Vlasenko2017-08-09 14:04:07 +0200
committerDenys Vlasenko2017-08-09 14:04:07 +0200
commitcde46f75cbe8069e06b68396a7f6dc9564fbf2c4 (patch)
tree2406602d311b0c20d220481f7f84802caf2490f7 /shell/shell_common.c
parent1f41c885fcafc67c9e957b74ab9d223e09ff949a (diff)
downloadbusybox-cde46f75cbe8069e06b68396a7f6dc9564fbf2c4.zip
busybox-cde46f75cbe8069e06b68396a7f6dc9564fbf2c4.tar.gz
shell: more efficient check for EOL in read
function old new delta shell_builtin_read 1334 1320 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r--shell/shell_common.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 2db8ea3..7a0799e 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -65,6 +65,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
int nchars; /* -n NUM */
char **pp;
char *buffer;
+ char delim;
struct termios tty, old_tty;
const char *retval;
int bufpos; /* need to be able to hold -1 */
@@ -185,6 +186,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
end_ms += (unsigned)monotonic_ms();
buffer = NULL;
bufpos = 0;
+ delim = opt_d ? *opt_d : '\n';
do {
char c;
int timeout;
@@ -238,10 +240,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
continue;
}
}
- if (opt_d) {
- if (c == *opt_d)
- break;
- } else if (c == '\n')
+ if (c == delim) /* '\n' or -d CHAR */
break;
/* $IFS splitting. NOT done if we run "read"