OSDN Git Service

Upgrade to mksh R56b.
[android-x86/external-mksh.git] / src / exec.c
index 6307bce..56a42f6 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "sh.h"
 
-__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.196 2017/04/12 16:46:21 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.199 2017/08/07 21:16:31 tg Exp $");
 
 #ifndef MKSH_DEFAULT_EXECSHELL
 #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@@ -554,6 +554,9 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
                                }
                        ap += builtin_opt.optind;
                        flags |= XEXEC;
+                       /* POSuX demands ksh88-like behaviour here */
+                       if (Flag(FPOSIX))
+                               fcflags = FC_PATH;
                } else if (tp->val.f == c_command) {
                        bool saw_p = false;
 
@@ -885,7 +888,9 @@ scriptexec(struct op *tp, const char **ap)
 #ifndef MKSH_SMALL
        if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) {
                unsigned char *cp;
+#ifndef MKSH_EBCDIC
                unsigned short m;
+#endif
                ssize_t n;
 
 #if defined(__OS2__) && defined(MKSH_WITH_TEXTMODE)
@@ -905,7 +910,7 @@ scriptexec(struct op *tp, const char **ap)
                    (buf[2] == 0xBF)) ? 3 : 0);
 
                /* scan for newline or NUL (end of buffer) */
-               while (*cp && *cp != '\n')
+               while (!ctype(*cp, C_NL | C_NUL))
                        ++cp;
                /* if the shebang line is longer than MAXINTERP, bail out */
                if (!*cp)
@@ -920,13 +925,13 @@ scriptexec(struct op *tp, const char **ap)
                        cp += 2;
 #ifdef __OS2__
                else if (!strncmp(cp, Textproc, 7) &&
-                   (cp[7] == ' ' || cp[7] == '\t'))
+                   ctype(cp[7], C_BLANK))
                        cp += 8;
 #endif
                else
                        goto noshebang;
                /* skip whitespace before shell name */
-               while (*cp == ' ' || *cp == '\t')
+               while (ctype(*cp, C_BLANK))
                        ++cp;
                /* just whitespace on the line? */
                if (*cp == '\0')
@@ -934,13 +939,13 @@ scriptexec(struct op *tp, const char **ap)
                /* no, we actually found an interpreter name */
                sh = (char *)cp;
                /* look for end of shell/interpreter name */
-               while (*cp != ' ' && *cp != '\t' && *cp != '\0')
+               while (!ctype(*cp, C_BLANK | C_NUL))
                        ++cp;
                /* any arguments? */
                if (*cp) {
                        *cp++ = '\0';
                        /* skip spaces before arguments */
-                       while (*cp == ' ' || *cp == '\t')
+                       while (ctype(*cp, C_BLANK))
                                ++cp;
                        /* pass it all in ONE argument (historic reasons) */
                        if (*cp)
@@ -959,6 +964,7 @@ scriptexec(struct op *tp, const char **ap)
 #endif
                goto nomagic;
  noshebang:
+#ifndef MKSH_EBCDIC
                m = buf[0] << 8 | buf[1];
                if (m == 0x7F45 && buf[2] == 'L' && buf[3] == 'F')
                        errorf("%s: not executable: %d-bit ELF file", tp->str,
@@ -977,6 +983,7 @@ scriptexec(struct op *tp, const char **ap)
                    buf[4] == 'Z') || (m == /* 7zip */ 0x377A) ||
                    (m == /* gzip */ 0x1F8B) || (m == /* .Z */ 0x1F9D))
                        errorf("%s: not executable: magic %04X", tp->str, m);
+#endif
 #ifdef __OS2__
                cp = _getext(tp->str);
                if (cp && (!stricmp(cp, ".cmd") || !stricmp(cp, ".bat"))) {
@@ -1337,7 +1344,7 @@ search_path(const char *name, const char *lpath,
        while (sp != NULL) {
                xp = Xstring(xs, xp);
                if (!(p = cstrchr(sp, MKSH_PATHSEPC)))
-                       p = sp + strlen(sp);
+                       p = strnul(sp);
                if (p != sp) {
                        XcheckN(xs, xp, p - sp);
                        memcpy(xp, sp, p - sp);