]> granicus.if.org Git - php/commitdiff
- Virtual current working directory is now enabled
authorAndi Gutmans <andi@php.net>
Tue, 23 May 2000 17:02:21 +0000 (17:02 +0000)
committerAndi Gutmans <andi@php.net>
Tue, 23 May 2000 17:02:21 +0000 (17:02 +0000)
- Added support for mkdir()/rmdir() and more

ext/standard/file.c
main/php.h
main/php_virtual_cwd.c
main/php_virtual_cwd.h

index 57569e73b0d3e2e0f2b63c62f20b0e8fc23ffedd..d129f6b8926e1e24ac1c510cb11e47c921410c18 100644 (file)
@@ -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;
index 9cc2f8b0404b89412b32902e3832f5afcd8cf4c1..e6f391d4a26ff1f308c210bd2dbe3af8d2cad734 100644 (file)
@@ -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"
index 765d3215d99372db73815bc5b08bef83f535b210..3676e160bb49acbd5f02cc1a480b9f1c27dac56a 100644 (file)
@@ -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;
 }
index c893c8d02006166b3f5d4295bb5bc53b2e30364b..dfd810a11886fb4ac5718706795c91796f01127c 100644 (file)
@@ -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);