summaryrefslogtreecommitdiff
path: root/TSRM
diff options
context:
space:
mode:
Diffstat (limited to 'TSRM')
-rw-r--r--TSRM/tsrm_virtual_cwd.c26
-rw-r--r--TSRM/tsrm_win32.c7
-rw-r--r--TSRM/tsrm_win32.h1
3 files changed, 8 insertions, 26 deletions
diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c
index ce4f2538f2..bb5bac0c3a 100644
--- a/TSRM/tsrm_virtual_cwd.c
+++ b/TSRM/tsrm_virtual_cwd.c
@@ -799,33 +799,9 @@ CWD_API DIR *virtual_opendir(const char *pathname TSRMLS_DC)
#ifdef TSRM_WIN32
-/* On Windows the trick of prepending "cd cwd; " doesn't work so we need to perform
- a real chdir() and mutex it
- */
CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
{
- char prev_cwd[MAXPATHLEN];
- char *getcwd_result;
- FILE *retval;
-
- getcwd_result = getcwd(prev_cwd, MAXPATHLEN);
- if (!getcwd_result) {
- return NULL;
- }
-
-#ifdef ZTS
- tsrm_mutex_lock(cwd_mutex);
-#endif
-
- chdir(CWDG(cwd).cwd);
- retval = popen(command, type);
- chdir(prev_cwd);
-
-#ifdef ZTS
- tsrm_mutex_unlock(cwd_mutex);
-#endif
-
- return retval;
+ return popen_ex(command, type, CWDG(cwd).cwd, NULL);
}
#elif defined(NETWARE)
diff --git a/TSRM/tsrm_win32.c b/TSRM/tsrm_win32.c
index 691443a243..aecdec8810 100644
--- a/TSRM/tsrm_win32.c
+++ b/TSRM/tsrm_win32.c
@@ -149,6 +149,11 @@ static HANDLE dupHandle(HANDLE fh, BOOL inherit) {
TSRM_API FILE *popen(const char *command, const char *type)
{
+ return popen_ex(command, type, NULL, NULL);
+}
+
+TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
+{
FILE *stream = NULL;
int fno, str_len = strlen(type), read, mode;
STARTUPINFO startup;
@@ -190,7 +195,7 @@ TSRM_API FILE *popen(const char *command, const char *type)
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c "));
sprintf(cmd, "%s /c %s", TWG(comspec), command);
- if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
+ if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, env, cwd, &startup, &process)) {
return NULL;
}
free(cmd);
diff --git a/TSRM/tsrm_win32.h b/TSRM/tsrm_win32.h
index 5e6ec7ece7..0a78c39450 100644
--- a/TSRM/tsrm_win32.h
+++ b/TSRM/tsrm_win32.h
@@ -92,6 +92,7 @@ typedef struct {
TSRM_API void tsrm_win32_startup(void);
TSRM_API void tsrm_win32_shutdown(void);
+TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env);
TSRM_API FILE *popen(const char *command, const char *type);
TSRM_API int pclose(FILE *stream);