diff options
author | Sascha Schumann <sas@php.net> | 2000-08-20 14:29:00 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 2000-08-20 14:29:00 +0000 |
commit | 1d68a02df36170851b4c3e72faea43129022642e (patch) | |
tree | 30e9672cd229cac4cd65dce9f06d8fbf9474a446 /main | |
parent | 320105bcd8540a6673e54106c03d569249af48f9 (diff) | |
download | php-git-1d68a02df36170851b4c3e72faea43129022642e.tar.gz |
The status quo in PHP is that the current directory is initialized
to the directory where the executing script is located.
Since this needs to be implemented for all SAPI modules anyway, this
change moves the functionality to php_execute_script() and gets rid
of the per-module code.
Diffstat (limited to 'main')
-rw-r--r-- | main/main.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c index c39af4e537..936c66bd5a 100644 --- a/main/main.c +++ b/main/main.c @@ -1109,6 +1109,7 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_ { zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file, append_file; + char old_cwd[4096] = ""; SLS_FETCH(); php_hash_environment(ELS_C SLS_CC PLS_CC); @@ -1138,6 +1139,8 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_ if (setjmp(EG(bailout))!=0) { + if (old_cwd[0] != '\0') + V_CHDIR(old_cwd); return; } @@ -1145,6 +1148,20 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_ UpdateIniFromRegistry(primary_file->filename); #endif + if (primary_file->type == ZEND_HANDLE_FILENAME + && primary_file->filename) { + char *filename; + + filename = strrchr(primary_file->filename, PHP_SEPARATOR); + + if (filename) { + filename++; + V_GETCWD(old_cwd, sizeof(old_cwd)-1); + V_CHDIR_FILE(primary_file->filename); + primary_file->filename = filename; + } + } + if (PG(auto_prepend_file) && PG(auto_prepend_file)[0]) { prepend_file.filename = PG(auto_prepend_file); prepend_file.opened_path = NULL; @@ -1164,6 +1181,9 @@ PHPAPI void php_execute_script(zend_file_handle *primary_file CLS_DC ELS_DC PLS_ append_file_p = NULL; } zend_execute_scripts(ZEND_REQUIRE CLS_CC ELS_CC, 3, prepend_file_p, primary_file, append_file_p); + + if (old_cwd[0] != '\0') + V_CHDIR(old_cwd); } PHPAPI int php_lint_script(zend_file_handle *file CLS_DC ELS_DC PLS_DC) |