aboutsummaryrefslogtreecommitdiff
path: root/shell/shell_common.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
committerRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
commitce9af1cc5ea23f754587448cf35b5120c77bfeef (patch)
tree69e5eaba5e75ab909ed92d5045393471b8ff3c13 /shell/shell_common.c
parentc170026700eabb10147dd848c45c06995b43a32e (diff)
parente837a0dbbebf4229306df98fe9ee3b9bb30630c4 (diff)
downloadbusybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.gz
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.bz2
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'shell/shell_common.c')
-rw-r--r--shell/shell_common.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c
index 750adc5d8..bc34de404 100644
--- a/shell/shell_common.c
+++ b/shell/shell_common.c
@@ -58,7 +58,8 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
58 const char *opt_n, 58 const char *opt_n,
59 const char *opt_p, 59 const char *opt_p,
60 const char *opt_t, 60 const char *opt_t,
61 const char *opt_u 61 const char *opt_u,
62 const char *opt_d
62) 63)
63{ 64{
64 struct pollfd pfd[1]; 65 struct pollfd pfd[1];
@@ -68,6 +69,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
68 int nchars; /* -n NUM */ 69 int nchars; /* -n NUM */
69 char **pp; 70 char **pp;
70 char *buffer; 71 char *buffer;
72 char delim;
71 struct termios tty, old_tty; 73 struct termios tty, old_tty;
72 const char *retval; 74 const char *retval;
73 int bufpos; /* need to be able to hold -1 */ 75 int bufpos; /* need to be able to hold -1 */
@@ -188,6 +190,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
188 end_ms += (unsigned)monotonic_ms(); 190 end_ms += (unsigned)monotonic_ms();
189 buffer = NULL; 191 buffer = NULL;
190 bufpos = 0; 192 bufpos = 0;
193 delim = opt_d ? *opt_d : '\n';
191 do { 194 do {
192 char c; 195 char c;
193 int timeout; 196 int timeout;
@@ -243,14 +246,14 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val),
243 continue; 246 continue;
244 } 247 }
245 } 248 }
246 if (c == '\n') 249 if (c == delim) /* '\n' or -d CHAR */
247 break; 250 break;
248 251
249 /* $IFS splitting. NOT done if we run "read" 252 /* $IFS splitting. NOT done if we run "read"
250 * without variable names (bash compat). 253 * without variable names (bash compat).
251 * Thus, "read" and "read REPLY" are not the same. 254 * Thus, "read" and "read REPLY" are not the same.
252 */ 255 */
253 if (argv[0]) { 256 if (!opt_d && argv[0]) {
254/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 */ 257/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 */
255 const char *is_ifs = strchr(ifs, c); 258 const char *is_ifs = strchr(ifs, c);
256 if (startword && is_ifs) { 259 if (startword && is_ifs) {