Index: /branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c
===================================================================
--- /branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c	(revision 3929)
+++ /branches/libc-0.6/src/emx/src/lib/sys/__spawnve.c	(revision 3930)
@@ -509,20 +509,29 @@
 
                 /*
-                 * Squeeze the interpreter arguments + the program name into
-                 * the argument buffer after argv[0].
-                 * ASSUME that the arguments and program name require no escaping.
-                 */
-                size_t cchPgmName = strlen(pszPgmName);
-                int cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
-                BOOL fQuote = strpbrk(pszPgmName, " \t") != NULL;
-                cch = cchPgmName + cchInterpreterArgs + 2 + 2 * fQuote;
-
-                /* grow and shift the argument buffer. */
+                 * The original argv0 is replaced by the "program name".
+                 * The interpreter and its optional arguments are then inserted in front of that.
+                 *
+                 * ASSUMES that the arguments and program name require no escaping.
+                 * ASSUMES that enmMethod != args_unix, which is true at the time of writing.
+                 */
+                size_t offOldArg1         = strlen(pszArgsBuf) + 1;
+                size_t cchPgmName         = strlen(pszPgmName);
+                size_t cchInterpreter     = strlen(pszInterpreter);
+                BOOL   fQuote             = strpbrk(pszPgmName, " \t") != NULL;
+                int    cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
+                cch = cchInterpreter + 1 + cchInterpreterArgs + 1 + cchPgmName + 2*fQuote + 1 - offOldArg1;
+
+                /* Grow and shift the argument buffer. */
                 size_t cbToMove = cbArgs; /* (ADD modifies cbArgs) */
                 ADD(cch);
-                psz = pszArgsBuf + strlen(pszArgsBuf) + 1;
-                memmove(psz + cch, psz, cbToMove);
-
-                /* add arguments */
+                memmove(pszArgsBuf + cch + offOldArg1, pszArgsBuf + offOldArg1, cbToMove - offOldArg1);
+
+                /* New argv[0] = Interpreter name. */
+                psz = pszArgsBuf;
+                memcpy(psz, pszInterpreter, cchInterpreter);
+                psz += cchInterpreter;
+                *psz++ = '\0';
+
+                /* Add arguments after that (if present). */
                 if (pszInterpreterArgs)
                 {
@@ -532,5 +541,5 @@
                 }
 
-                /* script name */
+                /* Finally add the script name (previous szNativePath actually). */
                 if (fQuote)
                     *psz++ = '"';
@@ -565,4 +574,5 @@
                 /*
                  * Try execute it.
+                 * Note! pszPgmName = &szNativePath[0], so we're good here and if this loops.
                  */
                 LIBCLOG_MSG("Calling DosExecPgm pgm: %s args: %s\\0%s\\0\\0\n", pszPgmName, pszArgsBuf, pszArgsBuf + strlen(pszArgsBuf) + 1);
Index: /trunk/libc/src/kNIX/os2/__spawnve.c
===================================================================
--- /trunk/libc/src/kNIX/os2/__spawnve.c	(revision 3929)
+++ /trunk/libc/src/kNIX/os2/__spawnve.c	(revision 3930)
@@ -523,20 +523,29 @@
 
                 /*
-                 * Squeeze the interpreter arguments + the program name into
-                 * the argument buffer after argv[0].
-                 * ASSUME that the arguments and program name require no escaping.
-                 */
+                 * The original argv0 is replaced by the "program name".
+                 * The interpreter and its optional arguments are then inserted in front of that.
+                 *
+                 * ASSUMES that the arguments and program name require no escaping.
+                 * ASSUMES that enmMethod != args_unix, which is true at the time of writing.
+                 */
+                size_t offOldArg1         = strlen(pszArgsBuf) + 1;
                 size_t cchPgmName = strlen(pszPgmName);
-                int cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
+                size_t cchInterpreter     = strlen(pszInterpreter);
                 BOOL fQuote = strpbrk(pszPgmName, " \t") != NULL;
-                cch = cchPgmName + cchInterpreterArgs + 2 + 2 * fQuote;
-
-                /* grow and shift the argument buffer. */
+                int    cchInterpreterArgs = pszInterpreterArgs ? strlen(pszInterpreterArgs) : -1;
+                cch = cchInterpreter + 1 + cchInterpreterArgs + 1 + cchPgmName + 2 * fQuote + 1 - offOldArg1;
+
+                /* Grow and shift the argument buffer. */
                 size_t cbToMove = cbArgs; /* (ADD modifies cbArgs) */
                 ADD(cch);
-                psz = pszArgsBuf + strlen(pszArgsBuf) + 1;
-                memmove(psz + cch, psz, cbToMove);
-
-                /* add arguments */
+                memmove(pszArgsBuf + cch + offOldArg1, pszArgsBuf + offOldArg1, cbToMove - offOldArg1);
+
+                /* New argv[0] = Interpreter name. */
+                psz = pszArgsBuf;
+                memcpy(psz, pszInterpreter, cchInterpreter);
+                psz += cchInterpreter;
+                *psz++ = '\0';
+
+                /* Add arguments after that (if present). */
                 if (pszInterpreterArgs)
                 {
@@ -546,5 +555,5 @@
                 }
 
-                /* script name */
+                /* Finally add the script name (previous szNativePath actually). */
                 if (fQuote)
                     *psz++ = '"';
@@ -579,4 +588,5 @@
                 /*
                  * Try execute it.
+                 * Note! pszPgmName = &szNativePath[0], so we're good here and if this loops.
                  */
                 LIBCLOG_MSG("Calling DosExecPgm pgm: %s args: %s\\0%s\\0\\0\n", pszPgmName, pszArgsBuf, pszArgsBuf + strlen(pszArgsBuf) + 1);
