From: Andi Gutmans Date: Mon, 12 Jun 2000 18:48:18 +0000 (+0000) Subject: - Start of popen() fix for UNIX. Still unclear what we'll do on Windows. X-Git-Tag: php-4.0.1RC~254 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02c42362ffb0f548942f3cb6f45c465520bed8ce;p=php - Start of popen() fix for UNIX. Still unclear what we'll do on Windows. --- diff --git a/main/php.h b/main/php.h index 5af3f98e83..7f692ca19d 100644 --- a/main/php.h +++ b/main/php.h @@ -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" diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index ca598536d6..088fa4a014 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -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) diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h index 9d6150a07c..bfe9f08eb2 100644 --- a/main/php_virtual_cwd.h +++ b/main/php_virtual_cwd.h @@ -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);