diff options
-rw-r--r-- | shell/shell_common.c | 7 | ||||
-rw-r--r-- | shell/shell_common.h | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/shell/shell_common.c b/shell/shell_common.c index 2db8ea3e2..7a0799ed5 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), | |||
65 | int nchars; /* -n NUM */ | 65 | int nchars; /* -n NUM */ |
66 | char **pp; | 66 | char **pp; |
67 | char *buffer; | 67 | char *buffer; |
68 | char delim; | ||
68 | struct termios tty, old_tty; | 69 | struct termios tty, old_tty; |
69 | const char *retval; | 70 | const char *retval; |
70 | int bufpos; /* need to be able to hold -1 */ | 71 | 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), | |||
185 | end_ms += (unsigned)monotonic_ms(); | 186 | end_ms += (unsigned)monotonic_ms(); |
186 | buffer = NULL; | 187 | buffer = NULL; |
187 | bufpos = 0; | 188 | bufpos = 0; |
189 | delim = opt_d ? *opt_d : '\n'; | ||
188 | do { | 190 | do { |
189 | char c; | 191 | char c; |
190 | int timeout; | 192 | int timeout; |
@@ -238,10 +240,7 @@ shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), | |||
238 | continue; | 240 | continue; |
239 | } | 241 | } |
240 | } | 242 | } |
241 | if (opt_d) { | 243 | if (c == delim) /* '\n' or -d CHAR */ |
242 | if (c == *opt_d) | ||
243 | break; | ||
244 | } else if (c == '\n') | ||
245 | break; | 244 | break; |
246 | 245 | ||
247 | /* $IFS splitting. NOT done if we run "read" | 246 | /* $IFS splitting. NOT done if we run "read" |
diff --git a/shell/shell_common.h b/shell/shell_common.h index 1b79bffca..875fd9ea7 100644 --- a/shell/shell_common.h +++ b/shell/shell_common.h | |||
@@ -34,6 +34,11 @@ enum { | |||
34 | BUILTIN_READ_SILENT = 1 << 0, | 34 | BUILTIN_READ_SILENT = 1 << 0, |
35 | BUILTIN_READ_RAW = 1 << 1, | 35 | BUILTIN_READ_RAW = 1 << 1, |
36 | }; | 36 | }; |
37 | //TODO? do not provide bashisms if not asked for: | ||
38 | //#if !ENABLE_HUSH_BASH_COMPAT && !ENABLE_ASH_BASH_COMPAT | ||
39 | //#define shell_builtin_read(setvar,argv,ifs,read_flags,n,p,t,u,d) | ||
40 | // shell_builtin_read(setvar,argv,ifs,read_flags) | ||
41 | //#endif | ||
37 | const char* FAST_FUNC | 42 | const char* FAST_FUNC |
38 | shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), | 43 | shell_builtin_read(void FAST_FUNC (*setvar)(const char *name, const char *val), |
39 | char **argv, | 44 | char **argv, |