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.
{
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);
if (setjmp(EG(bailout))!=0) {
+ if (old_cwd[0] != '\0')
+ V_CHDIR(old_cwd);
return;
}
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;
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)
SG(server_context) = r;
php_save_umask();
- V_CHDIR_FILE(filename);
add_common_vars(r);
add_cgi_vars(r);
#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>
} 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;
}
#if WIN32|WINNT
# include <windows.h>
-# define PATH_DELIMITER '\\'
-#else
-# define PATH_DELIMITER '/'
#endif
#include "pi3web_sapi.h"
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;
DWORD fnWrapperProc(LPCONTROL_BLOCK lpCB)
{
zend_file_handle file_handle;
- char *path_end;
SLS_FETCH();
CLS_FETCH();
ELS_FETCH();
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;
#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;