if (sapi_module.get_stat) {
return sapi_module.get_stat(SLS_C);
} else {
- if (!SG(request_info).path_translated || (stat(SG(request_info).path_translated, &SG(global_stat))==-1)) {
+ if (!SG(request_info).path_translated || (V_STAT(SG(request_info).path_translated, &SG(global_stat))==-1)) {
return NULL;
}
return &SG(global_stat);
}
snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename);
if (PG(safe_mode)) {
- if (stat(trypath, &sb) == 0 && (!php_checkuid(trypath, cm))) {
+ if (V_STAT(trypath, &sb) == 0 && (!php_checkuid(trypath, cm))) {
efree(pathbuf);
return NULL;
}
#define V_CHDIR(path) virtual_chdir(path)
#define V_CHDIR_FILE(path) virtual_chdir_file(path)
#define V_GETWD(buf)
+#define V_STAT(path, buff) virtual_stat(path, buff)
#else
#define V_GETCWD(buff, size) getcwd(buff,size)
#define V_FOPEN(path, mode) fopen(path, mode)
#define V_CHDIR(path) chdir(path)
#define V_CHDIR_FILE(path) chdir_file(path)
#define V_GETWD(buf) getwd(buf)
+#define V_STAT(path, buff) stat(path, buff)
#endif
#include "zend_constants.h"
}
/* Check if the resolved path is a directory */
- if (stat(path_construction, &filestat) != 0) return NULL;
+ if (V_STAT(path_construction, &filestat) != 0) return NULL;
if (S_ISDIR(filestat.st_mode)) {
/* It's a directory, append a / if needed */
if (*(writepos-1) != '/') {
#include <stdlib.h>
#include <ctype.h>
+
#include "php_virtual_cwd.h"
#ifdef ZTS
return f;
}
+CWD_API int virtual_stat(const char *path, struct stat *buf)
+{
+ cwd_state new_state;
+ int retval;
+ 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;
+}
+
#if 0
main(void)
#include "zend.h"
#include "zend_API.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifndef ZEND_WIN32
+#include <unistd.h>
+#endif
+
+
#ifdef PHP_EXPORTS
#define CWD_EXPORTS
#endif
CWD_API int virtual_chdir_file(char *path);
CWD_API int virtual_filepath(char *path, char **filepath);
CWD_API FILE *virtual_fopen(const char *path, const char *mode);
+CWD_API int virtual_stat(const char *path, struct stat *buf);
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
ZEND_BEGIN_MODULE_GLOBALS(cwd)
}
if (mode<3) {
- ret = stat(fn,&sb);
+ ret = V_STAT(fn,&sb);
if (ret<0 && mode < 2) {
php_error(E_WARNING,"Unable to access %s",fn);
return(mode);
if (s) {
*s='\0';
- ret = stat(fn,&sb);
+ ret = V_STAT(fn,&sb);
*s='/';
if (ret<0) {
php_error(E_WARNING, "Unable to access %s",fn);
php_error(E_WARNING, "Unable to access current working directory");
return(0);
}
- ret = stat(s,&sb);
+ ret = V_STAT(s,&sb);
efree(s);
if (ret<0) {
php_error(E_WARNING, "Unable to access %s",s);