summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-05-23 17:02:21 +0000
committerAndi Gutmans <andi@php.net>2000-05-23 17:02:21 +0000
commit617266e33efa1739e76dc8a2e34d028f80815ac2 (patch)
treec92d0bb864df1d6feec5efebb04bd697f9f19223
parent417f74451f1252b6153b34e09cfaebf104c24987 (diff)
downloadphp-git-617266e33efa1739e76dc8a2e34d028f80815ac2.tar.gz
- Virtual current working directory is now enabled
- Added support for mkdir()/rmdir() and more
-rw-r--r--ext/standard/file.c2
-rw-r--r--main/php.h6
-rw-r--r--main/php_virtual_cwd.c43
-rw-r--r--main/php_virtual_cwd.h2
4 files changed, 44 insertions, 9 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 57569e73b0..d129f6b892 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -1232,7 +1232,7 @@ PHP_FUNCTION(mkdir)
if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val,3))) {
RETURN_FALSE;
}
- ret = mkdir((*arg1)->value.str.val,mode);
+ ret = V_MKDIR((*arg1)->value.str.val,mode);
if (ret < 0) {
php_error(E_WARNING,"MkDir failed (%s)", strerror(errno));
RETURN_FALSE;
diff --git a/main/php.h b/main/php.h
index 9cc2f8b040..e6f391d4a2 100644
--- a/main/php.h
+++ b/main/php.h
@@ -289,7 +289,7 @@ PHPAPI int cfg_get_string(char *varname, char **result);
#define PUTS_H(str) php_header_write((str), strlen((str)))
#define PUTC_H(c) (php_header_write(&(c), 1), (c))
-/* #define VIRTUAL_DIR */
+#define VIRTUAL_DIR
#include "php_virtual_cwd.h"
/* Virtual current directory support */
@@ -309,6 +309,8 @@ PHPAPI int cfg_get_string(char *varname, char **result);
#define V_LSTAT(path, buff) virtual_lstat(path, buff)
#endif
#define V_UNLINK(path) virtual_unlink(path)
+#define V_MKDIR(pathname, mode) virtual_mkdir(pathname, mode)
+#define V_RMDIR(pathname) virtual_rmdir(pathname)
#else
#define V_GETCWD(buff, size) getcwd(buff,size)
#define V_FOPEN(path, mode) fopen(path, mode)
@@ -320,6 +322,8 @@ PHPAPI int cfg_get_string(char *varname, char **result);
#define V_STAT(path, buff) stat(path, buff)
#define V_LSTAT(path, buff) lstat(path, buff)
#define V_UNLINK(path) unlink(path)
+#define V_MKDIR(pathname, mode) mkdir(pathname, mode)
+#define V_RMDIR(pathname) rmdir(pathname)
#endif
#include "zend_constants.h"
diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c
index 765d3215d9..3676e160bb 100644
--- a/main/php_virtual_cwd.c
+++ b/main/php_virtual_cwd.c
@@ -373,9 +373,10 @@ CWD_API int virtual_filepath(char *path, char **filepath)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
retval = virtual_file_ex(&new_state, path, php_is_file_ok);
+
*filepath = new_state.cwd;
+
return retval;
}
@@ -386,10 +387,10 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
f = fopen(new_state.cwd, mode);
+
CWD_STATE_FREE(&new_state);
return f;
}
@@ -401,7 +402,6 @@ CWD_API int virtual_open(const char *path, int flags, ...)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
if (flags & O_CREAT) {
@@ -427,7 +427,6 @@ CWD_API int virtual_creat(const char *path, mode_t mode)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
f = open(new_state.cwd, O_CREAT | O_TRUNC, mode);
@@ -444,10 +443,10 @@ CWD_API int virtual_stat(const char *path, struct stat *buf)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
retval = stat(new_state.cwd, buf);
+
CWD_STATE_FREE(&new_state);
return retval;
}
@@ -461,10 +460,10 @@ CWD_API int virtual_lstat(const char *path, struct stat *buf)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
retval = lstat(new_state.cwd, buf);
+
CWD_STATE_FREE(&new_state);
return retval;
}
@@ -478,10 +477,40 @@ CWD_API int virtual_unlink(const char *path)
CWDLS_FETCH();
CWD_STATE_COPY(&new_state, &CWDG(cwd));
-
virtual_file_ex(&new_state, path, NULL);
retval = unlink(new_state.cwd);
+
+ CWD_STATE_FREE(&new_state);
+ return retval;
+}
+
+CWD_API int virtual_mkdir(const char *pathname, mode_t mode)
+{
+ cwd_state new_state;
+ int retval;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, pathname, NULL);
+
+ retval = mkdir(new_state.cwd, mode);
+
+ CWD_STATE_FREE(&new_state);
+ return retval;
+}
+
+CWD_API int virtual_rmdir(const char *pathname)
+{
+ cwd_state new_state;
+ int retval;
+ CWDLS_FETCH();
+
+ CWD_STATE_COPY(&new_state, &CWDG(cwd));
+ virtual_file_ex(&new_state, pathname, NULL);
+
+ retval = rmdir(new_state.cwd);
+
CWD_STATE_FREE(&new_state);
return retval;
}
diff --git a/main/php_virtual_cwd.h b/main/php_virtual_cwd.h
index c893c8d020..dfd810a118 100644
--- a/main/php_virtual_cwd.h
+++ b/main/php_virtual_cwd.h
@@ -49,6 +49,8 @@ CWD_API int virtual_stat(const char *path, struct stat *buf);
CWD_API int virtual_lstat(const char *path, struct stat *buf);
#endif
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 int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);