summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-03-19 21:10:48 +0000
committerAndi Gutmans <andi@php.net>2000-03-19 21:10:48 +0000
commit1c8c9ad2314152bb800f294004ece2e3f1345b98 (patch)
tree4a4c4c8084c5714e72336b00facb259ee0937ab1
parent073b7acc900c6c722e2eb26c52f877b0dab9a47c (diff)
downloadphp-git-1c8c9ad2314152bb800f294004ece2e3f1345b98.tar.gz
- 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).
-rw-r--r--main/php_virtual_cwd.c27
1 files changed, 25 insertions, 2 deletions
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)