Changeset 3930


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.

Files:
2 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);
  • trunk/libc/src/kNIX/os2/__spawnve.c

    r3904 r3930  
    523523
    524524                /*
    525                  * Squeeze the interpreter arguments + the program name into
    526                  * the argument buffer after argv[0].
    527                  * ASSUME that the arguments and program name require no escaping.
    528                  */
     525                 * The original argv0 is replaced by the "program name".
     526                 * The interpreter and its optional arguments are then inserted in front of that.
     527                 *
     528                 * ASSUMES that the arguments and program name require no escaping.
     529                 * ASSUMES that enmMethod != args_unix, which is true at the time of writing.
     530                 */
     531                size_t offOldArg1         = strlen(pszArgsBuf) + 1;
    529532                size_t cchPgmName = strlen(pszPgmName);
    530                 int cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
     533                size_t cchInterpreter     = strlen(pszInterpreter);
    531534                BOOL fQuote = strpbrk(pszPgmName, " \t") != NULL;
    532                 cch = cchPgmName + cchInterpreterArgs + 2 + 2 * fQuote;
    533 
    534                 /* grow and shift the argument buffer. */
     535                int    cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
     536                cch = cchInterpreter + 1 + cchInterpreterArgs + 1 + cchPgmName + 2 * fQuote + 1 - offOldArg1;
     537
     538                /* Grow and shift the argument buffer. */
    535539                size_t cbToMove = cbArgs; /* (ADD modifies cbArgs) */
    536540                ADD(cch);
    537                 psz = pszArgsBuf + strlen(pszArgsBuf) + 1;
    538                 memmove(psz + cch, psz, cbToMove);
    539 
    540                 /* add arguments */
     541                memmove(pszArgsBuf + cch + offOldArg1, pszArgsBuf + offOldArg1, cbToMove - offOldArg1);
     542
     543                /* New argv[0] = Interpreter name. */
     544                psz = pszArgsBuf;
     545                memcpy(psz, pszInterpreter, cchInterpreter);
     546                psz += cchInterpreter;
     547                *psz++ = '\0';
     548
     549                /* Add arguments after that (if present). */
    541550                if (pszInterpreterArgs)
    542551                {
     
    546555                }
    547556
    548                 /* script name */
     557                /* Finally add the script name (previous szNativePath actually). */
    549558                if (fQuote)
    550559                    *psz++ = '"';
     
    579588                /*
    580589                 * Try execute it.
     590                 * Note! pszPgmName = &szNativePath[0], so we're good here and if this loops.
    581591                 */
    582592                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.