aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-07-15 18:03:56 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-07-15 18:03:56 +0200
commitb0441a7189c874808dcfc36567d3e878c6ec7ba3 (patch)
tree9a28c747b854e5075f3eed1f661c1bf6937a02a3
parent8717b14f376e38998512c022b3d2b1af6e877e5e (diff)
downloadbusybox-w32-b0441a7189c874808dcfc36567d3e878c6ec7ba3.tar.gz
busybox-w32-b0441a7189c874808dcfc36567d3e878c6ec7ba3.tar.bz2
busybox-w32-b0441a7189c874808dcfc36567d3e878c6ec7ba3.zip
hush: shrink code in builtin_eval
function old new delta builtin_eval 126 119 -7 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/hush.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 1f83267be..9d3f06db0 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -9806,41 +9806,41 @@ static int FAST_FUNC builtin_pwd(char **argv UNUSED_PARAM)
9806 9806
9807static int FAST_FUNC builtin_eval(char **argv) 9807static int FAST_FUNC builtin_eval(char **argv)
9808{ 9808{
9809 int rcode = EXIT_SUCCESS;
9810
9811 argv = skip_dash_dash(argv); 9809 argv = skip_dash_dash(argv);
9812 if (argv[0]) {
9813 char *str = NULL;
9814 9810
9815 if (argv[1]) { 9811 if (!argv[0])
9816 /* "The eval utility shall construct a command by 9812 return EXIT_SUCCESS;
9817 * concatenating arguments together, separating
9818 * each with a <space> character."
9819 */
9820 char *p;
9821 unsigned len = 0;
9822 char **pp = argv;
9823 do
9824 len += strlen(*pp) + 1;
9825 while (*++pp);
9826 str = p = xmalloc(len);
9827 pp = argv;
9828 do {
9829 p = stpcpy(p, *pp);
9830 *p++ = ' ';
9831 } while (*++pp);
9832 p[-1] = '\0';
9833 }
9834 9813
9814 if (!argv[1]) {
9835 /* bash: 9815 /* bash:
9836 * eval "echo Hi; done" ("done" is syntax error): 9816 * eval "echo Hi; done" ("done" is syntax error):
9837 * "echo Hi" will not execute too. 9817 * "echo Hi" will not execute too.
9838 */ 9818 */
9839 parse_and_run_string(str ? str : argv[0]); 9819 parse_and_run_string(argv[0]);
9820 } else {
9821 /* "The eval utility shall construct a command by
9822 * concatenating arguments together, separating
9823 * each with a <space> character."
9824 */
9825 char *str, *p;
9826 unsigned len = 0;
9827 char **pp = argv;
9828 do
9829 len += strlen(*pp) + 1;
9830 while (*++pp);
9831 str = p = xmalloc(len);
9832 pp = argv;
9833 for (;;) {
9834 p = stpcpy(p, *pp);
9835 pp++;
9836 if (!*pp)
9837 break;
9838 *p++ = ' ';
9839 }
9840 parse_and_run_string(str);
9840 free(str); 9841 free(str);
9841 rcode = G.last_exitcode;
9842 } 9842 }
9843 return rcode; 9843 return G.last_exitcode;
9844} 9844}
9845 9845
9846static int FAST_FUNC builtin_exec(char **argv) 9846static int FAST_FUNC builtin_exec(char **argv)