Changeset 3930 for branches/libc-0.6


Ignore:
Timestamp:
Oct 26, 2014, 5:18:37 AM (11 years ago)
Author:
bird
Message:

trunk,0.6: Fixed hash-bang and batch script handling in spawnvpe. Fixes #307.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c

    r3903 r3930  
    509509
    510510                /*
    511                  * Squeeze the interpreter arguments + the program name into
    512                  * the argument buffer after argv[0].
    513                  * ASSUME that the arguments and program name require no escaping.
    514                  */
    515                 size_t cchPgmName = strlen(pszPgmName);
    516                 int cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
    517                 BOOL fQuote = strpbrk(pszPgmName, " \t") != NULL;
    518                 cch = cchPgmName + cchInterpreterArgs + 2 + 2 * fQuote;
    519 
    520                 /* grow and shift the argument buffer. */
     511                 * The original argv0 is replaced by the "program name".
     512                 * The interpreter and its optional arguments are then inserted in front of that.
     513                 *
     514                 * ASSUMES that the arguments and program name require no escaping.
     515                 * ASSUMES that enmMethod != args_unix, which is true at the time of writing.
     516                 */
     517                size_t offOldArg1         = strlen(pszArgsBuf) + 1;
     518                size_t cchPgmName         = strlen(pszPgmName);
     519                size_t cchInterpreter     = strlen(pszInterpreter);
     520                BOOL   fQuote             = strpbrk(pszPgmName, " \t") != NULL;
     521                int    cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
     522                cch = cchInterpreter + 1 + cchInterpreterArgs + 1 + cchPgmName + 2*fQuote + 1 - offOldArg1;
     523
     524                /* Grow and shift the argument buffer. */
    521525                size_t cbToMove = cbArgs; /* (ADD modifies cbArgs) */
    522526                ADD(cch);
    523                 psz = pszArgsBuf + strlen(pszArgsBuf) + 1;
    524                 memmove(psz + cch, psz, cbToMove);
    525 
    526                 /* add arguments */
     527                memmove(pszArgsBuf + cch + offOldArg1, pszArgsBuf + offOldArg1, cbToMove - offOldArg1);
     528
     529                /* New argv[0] = Interpreter name. */
     530                psz = pszArgsBuf;
     531                memcpy(psz, pszInterpreter, cchInterpreter);
     532                psz += cchInterpreter;
     533                *psz++ = '\0';
     534
     535                /* Add arguments after that (if present). */
    527536                if (pszInterpreterArgs)
    528537                {
     
    532541                }
    533542
    534                 /* script name */
     543                /* Finally add the script name (previous szNativePath actually). */
    535544                if (fQuote)
    536545                    *psz++ = '"';
     
    565574                /*
    566575                 * Try execute it.
     576                 * Note! pszPgmName = &szNativePath[0], so we're good here and if this loops.
    567577                 */
    568578                LIBCLOG_MSG("Calling DosExecPgm pgm: %s args: %s\\0%s\\0\\0\n", pszPgmName, pszArgsBuf, pszArgsBuf + strlen(pszArgsBuf) + 1);
Note: See TracChangeset for help on using the changeset viewer.