tls: code shrink
[oweals/busybox.git] / shell / ash.c
index 88f2b5bd64e3283a1b87fb4f7e9ec5f5b1bca1da..04e4006c89d4b0a1b6680eb6e7d1a63090c0927d 100644 (file)
 //config:      at build time. Like applets, scripts can be run as
 //config:      'busybox SCRIPT ...' or by linking their name to the binary.
 //config:
+//config:      This also allows applets to be implemented as scripts: place
+//config:      the script in 'applets_sh' and a stub C file containing
+//config:      configuration in the appropriate subsystem directory.
+//config:
 //config:endif # ash options
 
 //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
@@ -2420,13 +2424,12 @@ setvar(const char *name, const char *val, int flags)
        }
 
        INT_OFF;
-       nameeq = ckmalloc(namelen + vallen + 2);
+       nameeq = ckzalloc(namelen + vallen + 2);
        p = mempcpy(nameeq, name, namelen);
        if (val) {
                *p++ = '=';
-               p = mempcpy(p, val, vallen);
+               memcpy(p, val, vallen);
        }
-       *p = '\0';
        vp = setvareq(nameeq, flags | VNOSAVE);
        INT_ON;
 
@@ -8017,9 +8020,6 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) const char *cmd, char **argv, c
 {
 #if ENABLE_FEATURE_SH_STANDALONE
        if (applet_no >= 0) {
-# if NUM_SCRIPTS > 0
-               if (applet_no < NUM_APPLETS)
-# endif
                if (APPLET_IS_NOEXEC(applet_no)) {
                        clearenv();
                        while (*envp)
@@ -8089,9 +8089,6 @@ static void shellexec(char *prog, char **argv, const char *path, int idx)
        if (strchr(prog, '/') != NULL
 #if ENABLE_FEATURE_SH_STANDALONE
         || (applet_no = find_applet_by_name(prog)) >= 0
-# if NUM_SCRIPTS > 0
-        || (applet_no = NUM_APPLETS + find_script_by_name(prog)) >= 0
-# endif
 #endif
        ) {
                tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) prog, argv, envp);
@@ -10193,10 +10190,6 @@ evalcommand(union node *cmd, int flags)
  */
                /* find_command() encodes applet_no as (-2 - applet_no) */
                int applet_no = (- cmdentry.u.index - 2);
-# if NUM_SCRIPTS > 0
-               /* Applets are ok, but not embedded scripts */
-               if (applet_no < NUM_APPLETS)
-# endif
                if (applet_no >= 0 && APPLET_IS_NOFORK(applet_no)) {
                        char **sv_environ;
 
@@ -12968,6 +12961,7 @@ parseheredoc(void)
        heredoclist = NULL;
 
        while (here) {
+               tokpushback = 0;
                setprompt_if(needprompt, 2);
                readtoken1(pgetc(), here->here->type == NHERE ? SQSYNTAX : DQSYNTAX,
                                here->eofmark, here->striptabs);
@@ -13379,11 +13373,6 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
 #if ENABLE_FEATURE_SH_STANDALONE
        {
                int applet_no = find_applet_by_name(name);
-# if NUM_SCRIPTS > 0
-               if (applet_no < 0)
-                       /* embedded script indices are offset by NUM_APPLETS */
-                       applet_no = NUM_APPLETS + find_script_by_name(name);
-# endif
                if (applet_no >= 0) {
                        entry->cmdtype = CMDNORMAL;
                        entry->u.index = -2 - applet_no;
@@ -14052,11 +14041,11 @@ procargs(char **argv)
        int login_sh;
 
        xargv = argv;
+       login_sh = xargv[0] && xargv[0][0] == '-';
 #if NUM_SCRIPTS > 0
        if (minusc)
                goto setarg0;
 #endif
-       login_sh = xargv[0] && xargv[0][0] == '-';
        arg0 = xargv[0];
        /* if (xargv[0]) - mmm, this is always true! */
                xargv++;
@@ -14164,7 +14153,11 @@ extern int etext();
  * is used to figure out how far we had gotten.
  */
 int ash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+#if NUM_SCRIPTS > 0
+int ash_main(int argc, char **argv)
+#else
 int ash_main(int argc UNUSED_PARAM, char **argv)
+#endif
 /* note: 'argc' is used only if embedded scripts are enabled */
 {
        volatile smallint state;