Browse Source

- Virtual current working directory is now enabled

- Added support for mkdir()/rmdir() and more
PHP-4.0.5
Andi Gutmans 26 years ago
parent
commit
617266e33e
  1. 2
      ext/standard/file.c
  2. 6
      main/php.h
  3. 43
      main/php_virtual_cwd.c
  4. 2
      main/php_virtual_cwd.h

2
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;

6
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"

43
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;
}

2
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);

Loading…
Cancel
Save