summaryrefslogtreecommitdiff
path: root/main/php_virtual_cwd.c
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-06-24 16:10:18 +0000
committerAndi Gutmans <andi@php.net>2000-06-24 16:10:18 +0000
commit4b5e7d6618f8ea1b3a9f24376593bb44abb8a1ae (patch)
tree496a52dcd684543f2cc1cedb96c7db69e8ed2d33 /main/php_virtual_cwd.c
parentdfaaa8ff953c5c9a947ae45f1d0eb060f23f7364 (diff)
downloadphp-git-4b5e7d6618f8ea1b3a9f24376593bb44abb8a1ae.tar.gz
- Only use VIRTUAL_DIR in ZTS mode until it is thoroughly tested.
- Mutex popen() in Windows as the UNIX trick doesn't work there.
Diffstat (limited to 'main/php_virtual_cwd.c')
-rw-r--r--main/php_virtual_cwd.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c
index efa4c965d7..abf0c2037b 100644
--- a/main/php_virtual_cwd.c
+++ b/main/php_virtual_cwd.c
@@ -12,10 +12,11 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: |
- | |
+ | Authors: Andi Gutmans <andi@zend.com> |
+ | Sascha Schumann <ss@schumann.cx> |
+----------------------------------------------------------------------+
- */
+*/
+
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
@@ -39,6 +40,11 @@
#include "TSRM.h"
#endif
+/* Only need mutex for popen() in Windows because it doesn't chdir() on UNIX */
+#ifdef ZEND_WIN32
+MUTEX_T cwd_mutex;
+#endif
+
ZEND_DECLARE_MODULE_GLOBALS(cwd);
cwd_state main_cwd_state; /* True global */
@@ -158,7 +164,7 @@ static void cwd_globals_dtor(zend_cwd_globals *cwd_globals)
CWD_API void virtual_cwd_startup(void)
{
- char cwd[1024]; /* Should probably use system define here */
+ char cwd[MAXPATHLEN]; /* Should probably use system define here */
char *result;
result = getcwd(cwd, sizeof(cwd));
@@ -169,6 +175,9 @@ CWD_API void virtual_cwd_startup(void)
main_cwd_state.cwd_length = strlen(cwd);
ZEND_INIT_MODULE_GLOBALS(cwd, cwd_globals_ctor, cwd_globals_dtor);
+#ifdef ZEND_WIN32
+ cwd_mutex = tsrm_mutex_alloc();
+#endif
}
CWD_API void virtual_cwd_activate(char *filename)
@@ -186,6 +195,10 @@ CWD_API void virtual_cwd_shutdown(void)
#ifndef ZTS
cwd_globals_dtor(&cwd_globals);
#endif
+#ifdef ZEND_WIN32
+ tsrm_mutex_free(cwd_mutex);
+#endif
+
free(main_cwd_state.cwd); /* Don't use CWD_STATE_FREE because the non global states will probably use emalloc()/efree() */
}
@@ -559,6 +572,8 @@ CWD_API DIR *virtual_opendir(const char *pathname)
return retval;
}
+#ifndef ZEND_WIN32
+
CWD_API FILE *virtual_popen(const char *command, const char *type)
{
int command_length;
@@ -593,6 +608,36 @@ CWD_API FILE *virtual_popen(const char *command, const char *type)
return retval;
}
+#else
+
+/* 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)
+{
+ char prev_cwd[MAXPATHLEN];
+ char *getcwd_result;
+ FILE *retval;
+ CWDLS_FETCH();
+
+ getcwd_result = getcwd(prev_cwd, MAXPATHLEN);
+ if (!getcwd_result) {
+ return NULL;
+ }
+
+ tsrm_mutex_lock(cwd_mutex);
+
+ chdir(CWDG(cwd).cwd);
+ retval = popen(command, type);
+ chdir(prev_cwd);
+
+ tsrm_mutex_unlock(cwd_mutex);
+
+ return retval;
+}
+
+#endif
+
#if 0
main(void)