]> granicus.if.org Git - php/commitdiff
- Start of popen() fix for UNIX. Still unclear what we'll do on Windows.
authorAndi Gutmans <andi@php.net>
Mon, 12 Jun 2000 18:48:18 +0000 (18:48 +0000)
committerAndi Gutmans <andi@php.net>
Mon, 12 Jun 2000 18:48:18 +0000 (18:48 +0000)
main/php.h
main/php_virtual_cwd.c
main/php_virtual_cwd.h

index 5af3f98e83feee998dce1b01e64ddb68da042512..7f692ca19d72b99d3aedecf7d9571f5922994c9a 100644 (file)
@@ -307,6 +307,7 @@ 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)
+#define V_POPEN(command, type) virtual_popen(command, type)
 #else
 #define V_GETCWD(buff, size) getcwd(buff,size)
 #define V_FOPEN(path, mode)  fopen(path, mode)
@@ -321,6 +322,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
 #define V_MKDIR(pathname, mode) mkdir(pathname, mode)
 #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 ca598536d663cc5148d1ae06e8086cde1fef707b..088fa4a014706a802422ba51ce365ec677002a8e 100644 (file)
@@ -555,6 +555,40 @@ CWD_API DIR *virtual_opendir(const char *pathname)
        return retval;
 }
 
+CWD_API FILE *virtual_popen(const char *command, const char *type)
+{
+       int command_length;
+       char *command_line;
+       char *ptr;
+       FILE *retval;
+       CWDLS_FETCH();
+
+       command_length = strlen(command);
+
+       ptr = command_line = (char *) malloc(command_length + sizeof("cd  ; ") + CWDG(cwd).cwd_length+1);
+       if (!command_line) {
+               return NULL;
+       }
+       memcpy(ptr, "cd ", sizeof("cd ")-1);
+       ptr += sizeof("cd ");
+
+       if (CWDG(cwd).cwd_length == 0) {
+               *ptr++ = DEFAULT_SLASH;
+       } else {
+               memcpy(ptr, CWDG(cwd).cwd, CWDG(cwd).cwd_length);
+               ptr += CWDG(cwd).cwd_length;
+       }
+       
+       *ptr++ = ' ';
+       *ptr++ = ';';
+       *ptr++ = ' ';
+
+       memcpy(ptr, command, command_length+1);
+       retval = popen(command_line, type);
+       free(command_line);
+       return retval;
+}
+
 #if 0
 
 main(void)
index 9d6150a07c147018bf66ee0435cb7b4d84d9ba5e..bfe9f08eb2826dfd53b6d72038345eb9f2b647dc 100644 (file)
@@ -59,6 +59,7 @@ CWD_API int virtual_unlink(const char *path);
 CWD_API int virtual_mkdir(const char *pathname, mode_t mode);
 CWD_API int virtual_rmdir(const char *pathname);
 CWD_API DIR *virtual_opendir(const char *pathname);
+CWD_API FILE *virtual_popen(const char *command, const char *type);
 
 CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);