1616#include <string.h>
1717#include <stdlib.h>
1818
19- #if _WIN32
20- #include <process.h>
21- #ifdef _MSC_VER
22- #include <windows.h>
23- #endif
24- #endif
25-
2619#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
2720#include <sys/types.h>
2821#include <sys/wait.h>
2922#include <unistd.h>
3023#endif
3124
32- #if __linux__ || __APPLE__
33- #define HAS_POSIX_SPAWN 1
34- #include <spawn.h>
35- #if __APPLE__
36- #include <crt_externs.h>
37- #endif
38- #else
39- #define HAS_POSIX_SPAWN 0
40- #endif
25+ #include "utils.h"
4126
4227#include "root.h"
4328
@@ -248,7 +233,7 @@ int runLINK()
248233
249234 /* Append the path to the VC lib files, and then the SDK lib files
250235 */
251- const char * vcinstalldir = getenv ("VCINSTALLDIR" );
236+ const char * vcinstalldir = dgetenv ("VCINSTALLDIR" );
252237 if (vcinstalldir )
253238 { cmdbuf .writestring (" /LIBPATH:\"" );
254239 cmdbuf .writestring (vcinstalldir );
@@ -258,7 +243,7 @@ int runLINK()
258243 cmdbuf .writestring ("\\lib\"" );
259244 }
260245
261- const char * windowssdkdir = getenv ("WindowsSdkDir" );
246+ const char * windowssdkdir = dgetenv ("WindowsSdkDir" );
262247 if (windowssdkdir )
263248 { cmdbuf .writestring (" /LIBPATH:\"" );
264249 cmdbuf .writestring (windowssdkdir );
@@ -284,9 +269,9 @@ int runLINK()
284269 sprintf (p , "@%s" , lnkfilename );
285270 }
286271
287- const char * linkcmd = getenv (global .params .is64bit ? "LINKCMD64" : "LINKCMD" );
272+ const char * linkcmd = dgetenv (global .params .is64bit ? "LINKCMD64" : "LINKCMD" );
288273 if (!linkcmd )
289- linkcmd = getenv ("LINKCMD" ); // backward compatible
274+ linkcmd = dgetenv ("LINKCMD" ); // backward compatible
290275 if (!linkcmd )
291276 {
292277 if (vcinstalldir )
@@ -435,7 +420,7 @@ int runLINK()
435420 sprintf (p , "@%s" , lnkfilename );
436421 }
437422
438- const char * linkcmd = getenv ("LINKCMD" );
423+ const char * linkcmd = dgetenv ("LINKCMD" );
439424 if (!linkcmd )
440425 linkcmd = "link" ;
441426 int status = executecmd (linkcmd , p );
@@ -747,7 +732,6 @@ int executecmd(const char *cmd, const char *args)
747732{
748733 int status ;
749734 size_t len ;
750-
751735 if (global .params .verbose )
752736 fprintf (global .stdmsg , "%s %s\n" , cmd , args );
753737
@@ -757,7 +741,7 @@ int executecmd(const char *cmd, const char *args)
757741 {
758742 char * q = (char * ) alloca (8 + len + 1 );
759743 sprintf (q ,"_CMDLINE=%s" , args );
760- status = putenv (q );
744+ status = dputenv (q );
761745 if (status == 0 )
762746 {
763747 args = "@_CMDLINE" ;
@@ -772,23 +756,10 @@ int executecmd(const char *cmd, const char *args)
772756 // Normalize executable path separators, see Bugzilla 9330
773757 cmd = toWinPath (cmd );
774758
775- #ifdef _MSC_VER
776- if (strchr (cmd , ' ' ))
777- {
778- // MSVCRT: spawn does not work with spaces in the executable
779- size_t cmdlen = strlen (cmd );
780- char * shortName = new char [cmdlen + 1 ]; // enough space
781- DWORD len = GetShortPathName (cmd , shortName , cmdlen + 1 );
782- if (len > 0 && len <= cmdlen )
783- cmd = shortName ;
784- }
785- #endif
786-
787759 status = executearg0 (cmd ,args );
788760 if (status == -1 )
789761 {
790- // spawnlp returns intptr_t in some systems, not int
791- status = spawnlp (0 ,cmd ,cmd ,args ,NULL );
762+ status = dspawnlp (0 ,cmd ,cmd ,args ,NULL );
792763 }
793764
794765// if (global.params.verbose)
@@ -827,8 +798,7 @@ int executearg0(const char *cmd, const char *args)
827798 file = FileName ::replaceName (argv0 , cmd );
828799
829800 //printf("spawning '%s'\n",file);
830- // spawnlp returns intptr_t in some systems, not int
831- return spawnl (0 ,file ,file ,args ,NULL );
801+ return dspawnl (0 ,file ,file ,args ,NULL );
832802}
833803#endif
834804
@@ -854,15 +824,6 @@ int runProgram()
854824 argv .push (global .params .exefile );
855825 for (size_t i = 0 ; i < global .params .runargs_length ; i ++ )
856826 { const char * a = global .params .runargs [i ];
857-
858- #if _WIN32
859- // BUG: what about " appearing in the string?
860- if (strchr (a , ' ' ))
861- { char * b = (char * )mem .xmalloc (3 + strlen (a ));
862- sprintf (b , "\"%s\"" , a );
863- a = b ;
864- }
865- #endif
866827 argv .push (a );
867828 }
868829 argv .push (NULL );
@@ -873,8 +834,7 @@ int runProgram()
873834 ex = FileName ::combine ("." , ex );
874835 else
875836 ex = global .params .exefile ;
876- // spawnlp returns intptr_t in some systems, not int
877- return spawnv (0 ,ex ,argv .tdata ());
837+ return dspawnv (0 ,ex ,argv .tdata ());
878838#elif __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
879839 pid_t childpid ;
880840 int status ;
0 commit comments