From: Andi Gutmans Date: Mon, 12 Jun 2000 19:39:04 +0000 (+0000) Subject: - On UNIX support popen() which works with current working directory X-Git-Tag: php-4.0.1RC~252 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=719d995a9df436998c5c1e22ec150a8e4c0d1d4f;p=php - On UNIX support popen() which works with current working directory - when in VIRTUAL_DIR mode. --- diff --git a/ext/standard/exec.c b/ext/standard/exec.c index ad57cfd266..7fc6acc033 100644 --- a/ext/standard/exec.c +++ b/ext/standard/exec.c @@ -87,9 +87,9 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value) efree(d); d = tmp; #ifdef PHP_WIN32 - fp = popen(d, "rb"); + fp = V_POPEN(d, "rb"); #else - fp = popen(d, "r"); + fp = V_POPEN(d, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", d); @@ -99,9 +99,9 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value) } } else { /* not safe_mode */ #ifdef PHP_WIN32 - fp = popen(cmd, "rb"); + fp = V_POPEN(cmd, "rb"); #else - fp = popen(cmd, "r"); + fp = V_POPEN(cmd, "r"); #endif if (!fp) { php_error(E_WARNING, "Unable to fork [%s]", cmd); @@ -364,9 +364,9 @@ PHP_FUNCTION(shell_exec) convert_to_string_ex(cmd); #ifdef PHP_WIN32 - if ((in=popen((*cmd)->value.str.val,"rt"))==NULL) { + if ((in=V_POPEN((*cmd)->value.str.val,"rt"))==NULL) { #else - if ((in=popen((*cmd)->value.str.val,"r"))==NULL) { + if ((in=V_POPEN((*cmd)->value.str.val,"r"))==NULL) { #endif php_error(E_WARNING,"Unable to execute '%s'",(*cmd)->value.str.val); } diff --git a/ext/standard/file.c b/ext/standard/file.c index bd7b7f90cb..fb34ad6f60 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -713,7 +713,7 @@ PHP_FUNCTION(popen) } tmp = php_escape_shell_cmd(buf); - fp = popen(tmp,p); + fp = V_POPEN(tmp,p); efree(tmp); if (!fp) { @@ -721,7 +721,7 @@ PHP_FUNCTION(popen) RETURN_FALSE; } } else { - fp = popen((*arg1)->value.str.val,p); + fp = V_POPEN((*arg1)->value.str.val,p); if (!fp) { php_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",(*arg1)->value.str.val,p,strerror(errno)); efree(p); diff --git a/main/php.h b/main/php.h index 7f692ca19d..ef79abba16 100644 --- a/main/php.h +++ b/main/php.h @@ -289,6 +289,7 @@ PHPAPI int cfg_get_string(char *varname, char **result); /* Virtual current directory support */ #ifdef VIRTUAL_DIR + #define V_GETCWD(buff, size) virtual_getcwd(buff,size) #define V_FOPEN(path, mode) virtual_fopen(path, mode) /* The V_OPEN macro will need to be used as V_OPEN((path, flags, ...)) */ @@ -307,8 +308,15 @@ PHPAPI int cfg_get_string(char *varname, char **result); #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 + #define V_GETCWD(buff, size) getcwd(buff,size) #define V_FOPEN(path, mode) fopen(path, mode) #define V_OPEN(open_args) open open_args @@ -323,6 +331,7 @@ PHPAPI int cfg_get_string(char *varname, char **result); #define V_RMDIR(pathname) rmdir(pathname) #define V_OPENDIR(pathname) opendir(pathname) #define V_POPEN(command, type) popen(command, type) + #endif #include "zend_constants.h" diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index 088fa4a014..2cb37d8ff5 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -570,7 +570,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type) return NULL; } memcpy(ptr, "cd ", sizeof("cd ")-1); - ptr += sizeof("cd "); + ptr += sizeof("cd ")-1; if (CWDG(cwd).cwd_length == 0) { *ptr++ = DEFAULT_SLASH;