From: Andi Gutmans Date: Sun, 19 Mar 2000 21:10:48 +0000 (+0000) Subject: - Quick fopen() support. The code needs some cleaning up and we might X-Git-Tag: PHP-4.0-RC1~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c8c9ad2314152bb800f294004ece2e3f1345b98;p=php - Quick fopen() support. The code needs some cleaning up and we might need to think of performance issues with the strdup()'s (definitely use strndup() and maybe try to do with less string copies). --- diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c index c3bd9ae0df..a4583fdca1 100644 --- a/main/php_virtual_cwd.c +++ b/main/php_virtual_cwd.c @@ -226,9 +226,32 @@ int virtual_chdir(cwd_state *state, char *path) return virtual_file_ex(state, path, NULL); /* Use NULL right now instead of php_is_dir_ok */ } -int virtual_filepath(cwd_state *state, char *path) +int virtual_filepath(cwd_state *state, char *path, char **filepath) { - return virtual_file_ex(state, path, php_is_file_ok); + cwd_state new_state = *state; + int retval; + + new_state.cwd = strdup(state->cwd); + retval = virtual_file_ex(&new_state, path, php_is_file_ok); + *filepath = new_state.cwd; + return retval; +} + +FILE *virtual_fopen(cwd_state *state, char *path, const char *mode) +{ + cwd_state new_state = *state; + FILE *f; + int retval; + + new_state.cwd = strdup(state->cwd); + retval = virtual_file_ex(&new_state, path, php_is_file_ok); + + if (retval) { + return NULL; + } + f = fopen(new_state.cwd, mode); + free(new_state.cwd); + return f; } main(void)