From: Sascha Schumann Date: Sun, 20 Aug 2000 14:29:00 +0000 (+0000) Subject: The status quo in PHP is that the current directory is initialized X-Git-Tag: php-4.0.2RC1~28 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d68a02df36170851b4c3e72faea43129022642e;p=php 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. --- 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) diff --git a/sapi/apache/mod_php4.c b/sapi/apache/mod_php4.c index 682d3eedfe..9999e0fdaa 100644 --- a/sapi/apache/mod_php4.c +++ b/sapi/apache/mod_php4.c @@ -496,7 +496,6 @@ int send_php(request_rec *r, int display_source_mode, char *filename) SG(server_context) = r; php_save_umask(); - V_CHDIR_FILE(filename); add_common_vars(r); add_cgi_vars(r); diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index 5cc2ba0019..461b9287ca 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -20,12 +20,10 @@ #ifdef PHP_WIN32 # include # include -# define SEPARATOR '\\' #else # define __try # define __except(val) # define __declspec(foo) -# define SEPARATOR '/' #endif #include @@ -482,15 +480,6 @@ static void init_request_info(sapi_globals_struct *sapi_globals, LPEXTENSION_CON } else { SG(request_info).headers_only = 0; } - { - char *path_end = strrchr(SG(request_info).path_translated, SEPARATOR); - - if (path_end) { - *path_end = 0; - V_CHDIR(SG(request_info).path_translated); - *path_end = SEPARATOR; - } - } if (!bFilterLoaded) { /* we don't have valid ISAPI Filter information */ SG(request_info).auth_user = SG(request_info).auth_password = NULL; } diff --git a/sapi/pi3web/pi3web_sapi.c b/sapi/pi3web/pi3web_sapi.c index ff2951e708..a9099e0b11 100644 --- a/sapi/pi3web/pi3web_sapi.c +++ b/sapi/pi3web/pi3web_sapi.c @@ -24,9 +24,6 @@ #if WIN32|WINNT # include -# define PATH_DELIMITER '\\' -#else -# define PATH_DELIMITER '/' #endif #include "pi3web_sapi.h" @@ -309,8 +306,8 @@ static sapi_module_struct sapi_module = { static void init_request_info(sapi_globals_struct *sapi_globals, LPCONTROL_BLOCK lpCB) { - char *path_end = strrchr(lpCB->lpszFileName, PATH_DELIMITER); - if ( path_end ) *path_end = PATH_DELIMITER; + char *path_end = strrchr(lpCB->lpszFileName, PHP_SEPARATOR); + if ( path_end ) *path_end = PHP_SEPARATOR; SG(server_context) = lpCB; SG(request_info).request_method = lpCB->lpszMethod; @@ -384,7 +381,6 @@ static void hash_pi3web_variables(ELS_D SLS_DC) DWORD fnWrapperProc(LPCONTROL_BLOCK lpCB) { zend_file_handle file_handle; - char *path_end; SLS_FETCH(); CLS_FETCH(); ELS_FETCH(); @@ -392,13 +388,6 @@ DWORD fnWrapperProc(LPCONTROL_BLOCK lpCB) if (setjmp( EG(bailout)) != 0 ) return PIAPI_ERROR; - path_end = strrchr( lpCB->lpszFileName, PATH_DELIMITER ); - if ( path_end ) { - *path_end = 0; - chdir( lpCB->lpszFileName ); - *path_end = PATH_DELIMITER; - }; - file_handle.filename = lpCB->lpszFileName; file_handle.free_filename = 0; file_handle.type = ZEND_HANDLE_FILENAME; diff --git a/sapi/roxen/roxen.c b/sapi/roxen/roxen.c index 62c17a7726..b2c0dbf8e5 100644 --- a/sapi/roxen/roxen.c +++ b/sapi/roxen/roxen.c @@ -593,19 +593,6 @@ static int php_roxen_module_main(SLS_D) #endif #endif -#ifdef VIRTUAL_DIR - /* Change virtual directory, if the feature is enabled */ - dir = malloc(len = strlen(THIS->filename)); - strcpy(dir, THIS->filename); - while(--len >= 0 && dir[len] != '/') - ; - if(len > 0) { - dir[len] = '\0'; - } - V_CHDIR(dir); - free(dir); -#endif - file_handle.type = ZEND_HANDLE_FILENAME; file_handle.filename = THIS->filename; file_handle.free_filename = 0;