]> granicus.if.org Git - php/commitdiff
The status quo in PHP is that the current directory is initialized
authorSascha Schumann <sas@php.net>
Sun, 20 Aug 2000 14:29:00 +0000 (14:29 +0000)
committerSascha Schumann <sas@php.net>
Sun, 20 Aug 2000 14:29:00 +0000 (14:29 +0000)
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.

main/main.c
sapi/apache/mod_php4.c
sapi/isapi/php4isapi.c
sapi/pi3web/pi3web_sapi.c
sapi/roxen/roxen.c

index c39af4e5377b3e7ea4ed0e316e5b88b8907ce02e..936c66bd5aa3a1cea4be82b5ee1564415141f333 100644 (file)
@@ -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)
index 682d3eedfe9331ad366ebe3e9c1bb5a6c8ac0f72..9999e0fdaa67aefe45c68c53ad272507ccff2c0c 100644 (file)
@@ -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);
 
index 5cc2ba0019ca0c1200fb89903e63dc5c652cca72..461b9287cadd2ec81e3fb38589a36cd7481decf7 100644 (file)
 #ifdef PHP_WIN32
 # include <windows.h>
 # include <process.h>
-# define SEPARATOR '\\'
 #else
 # define __try
 # define __except(val)
 # define __declspec(foo)
-# define SEPARATOR '/'
 #endif
 
 #include <httpext.h>
@@ -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;
        }
index ff2951e708f2d7e27912f3f837d018405ba92072..a9099e0b11df7051918a38e66d54829144d98016 100644 (file)
@@ -24,9 +24,6 @@
 
 #if WIN32|WINNT
 #  include <windows.h>
-#  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;
index 62c17a7726b84a1e9a189dff94fc3cf3670844a5..b2c0dbf8e59b63c4d72331d3ba847fa231804950 100644 (file)
@@ -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;