]> granicus.if.org Git - php/commitdiff
- On UNIX support popen() which works with current working directory
authorAndi Gutmans <andi@php.net>
Mon, 12 Jun 2000 19:39:04 +0000 (19:39 +0000)
committerAndi Gutmans <andi@php.net>
Mon, 12 Jun 2000 19:39:04 +0000 (19:39 +0000)
- when in VIRTUAL_DIR mode.

ext/standard/exec.c
ext/standard/file.c
main/php.h
main/php_virtual_cwd.c

index ad57cfd266990b4dce5ff900a7518d6b0ddf0fc5..7fc6acc033430c7657476e3efd6c13abe2529b17 100644 (file)
@@ -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);
        }
index bd7b7f90cbd542546fd44e3ac91d6c87b76564fb..fb34ad6f60e37035aa4106262cd08d632311d595 100644 (file)
@@ -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);
index 7f692ca19d72b99d3aedecf7d9571f5922994c9a..ef79abba16a2d2c19ed37d541f15aa2089c8735f 100644 (file)
@@ -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"
index 088fa4a014706a802422ba51ce365ec677002a8e..2cb37d8ff5559ec3bcda7fae6b40be70018ad694 100644 (file)
@@ -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;