4 #include "systeminfo.h"
9 static char *environment
;
12 * if we can't find path to msys in the registry, return NULL and
13 * the CreateProcess will copy the environment for us
15 if (!environment
&& msys_path()) {
16 char *old
= GetEnvironmentStrings();
17 size_t space
= 0, path_index
= -1, name_len
= 0, len2
;
20 /* if it's PATH variable (could be Path= too!) */
21 if (!strnicmp(old
+ space
, "PATH=", 5)) {
28 space
++; /* skip var-terminating NULL */
34 environment
= malloc(space
+
35 2 * strlen(msys_path()) + 32);
37 /* copy the block up to the equal sign of PATH var */
38 memcpy(environment
, old
, path_index
);
39 /* insert new segments of the PATH */
40 len2
= sprintf(environment
+ path_index
,
41 "PATH=%s\\bin;%s\\mingw\\bin%s",
42 msys_path(), msys_path(), name_len
? ";" : "");
43 /* append original value of PATH and variables after it */
44 memcpy(environment
+ path_index
+ len2
,
45 old
+ path_index
+ name_len
,
46 space
+ 1 - path_index
- name_len
);
48 FreeEnvironmentStrings(old
);
54 void exec_gui(char *command
, const char *wd
)
56 STARTUPINFO si
= { sizeof(si
) };
57 PROCESS_INFORMATION pi
;
59 si
.dwFlags
= STARTF_USESHOWWINDOW
;
60 si
.wShowWindow
= SW_HIDE
;
62 debug_git("Trying to spawn '%s' in working directory '%s'\n",
64 if (CreateProcess(NULL
, command
, NULL
, NULL
, FALSE
, 0,
65 env_for_git(), wd
, &si
, &pi
))
67 CloseHandle(pi
.hProcess
);
68 CloseHandle(pi
.hThread
);
71 debug_git("[ERROR] Could not create process (%d)"
73 GetLastError(), wd
, command
);