cvs: php4 /main php.h php_virtual_cwd.c php_virtual_cwd.h

From: Date: Sat, 24 Jun 2000 16:10:18 +0000
Subject: cvs: php4 /main php.h php_virtual_cwd.c php_virtual_cwd.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-425@lists.php.net to get a copy of this message
andi Sat Jun 24 09:10:18 2000 EDT Modified files: /php4/main php.h php_virtual_cwd.c php_virtual_cwd.h Log: - Only use VIRTUAL_DIR in ZTS mode until it is thoroughly tested. - Mutex popen() in Windows as the UNIX trick doesn't work there. Index: php4/main/php.h diff -u php4/main/php.h:1.105 php4/main/php.h:1.106 --- php4/main/php.h:1.105 Mon Jun 12 12:39:04 2000 +++ php4/main/php.h Sat Jun 24 09:10:18 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php.h,v 1.105 2000/06/12 19:39:04 andi Exp $ */ +/* $Id: php.h,v 1.106 2000/06/24 16:10:18 andi Exp $ */ #ifndef _PHP_H #define _PHP_H @@ -284,7 +284,10 @@ #define PUTS_H(str) php_header_write((str), strlen((str))) #define PUTC_H(c) (php_header_write(&(c), 1), (c)) +#ifdef ZTS #define VIRTUAL_DIR +#endif + #include "php_virtual_cwd.h" /* Virtual current directory support */ @@ -308,12 +311,7 @@ #define V_MKDIR(pathname, mode) virtual_mkdir(pathname, mode) #define V_RMDIR(pathname) virtual_rmdir(pathname) #define V_OPENDIR(pathname) virtual_opendir(pathname) -#ifdef PHP_WIN32 -/* Under Windows the "cd /cwd ; command" trick doesn't work */ -#define V_POPEN(command, type) popen(command, type) -#else #define V_POPEN(command, type) virtual_popen(command, type) -#endif #else Index: php4/main/php_virtual_cwd.c diff -u php4/main/php_virtual_cwd.c:1.55 php4/main/php_virtual_cwd.c:1.56 --- php4/main/php_virtual_cwd.c:1.55 Thu Jun 15 11:36:46 2000 +++ php4/main/php_virtual_cwd.c Sat Jun 24 09:10:18 2000 @@ -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 @@ 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 @@ 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 @@ #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 @@ return retval; } +#ifndef ZEND_WIN32 + CWD_API FILE *virtual_popen(const char *command, const char *type) { int command_length; @@ -592,6 +607,36 @@ free(command_line); 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 Index: php4/main/php_virtual_cwd.h diff -u php4/main/php_virtual_cwd.h:1.25 php4/main/php_virtual_cwd.h:1.26 --- php4/main/php_virtual_cwd.h:1.25 Mon Jun 12 11:48:18 2000 +++ php4/main/php_virtual_cwd.h Sat Jun 24 09:10:18 2000 @@ -1,3 +1,22 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Andi Gutmans <andi@zend.com> | + | Sascha Schumann <ss@schumann.cx> | + +----------------------------------------------------------------------+ +*/ + #ifndef VIRTUAL_CWD_H #define VIRTUAL_CWD_H

« previous php.cvs (#425) next »