summaryrefslogtreecommitdiff
path: root/main/streams/streams.c
diff options
context:
space:
mode:
authorSara Golemon <pollita@php.net>2003-11-28 23:25:28 +0000
committerSara Golemon <pollita@php.net>2003-11-28 23:25:28 +0000
commit026d4c9e4cec8cb3f03c311b90f05241f2d70455 (patch)
treee563b6f3699eb94168362c8f00fb1c4d80506e7a /main/streams/streams.c
parent6d86bb9e40386e4127af4f55b8e8e79864255ca1 (diff)
downloadphp-git-026d4c9e4cec8cb3f03c311b90f05241f2d70455.tar.gz
Route php_stat() via streams/url_stat API (php_stream_stat_path).
This enables fopen-wrappers support on stat() and related family calls.
Diffstat (limited to 'main/streams/streams.c')
-rwxr-xr-xmain/streams/streams.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/main/streams/streams.c b/main/streams/streams.c
index 2089281741..c612e4ca4d 100755
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1458,14 +1458,45 @@ PHPAPI php_stream_wrapper *php_stream_locate_url_wrapper(const char *path, char
/* }}} */
/* {{{ _php_stream_stat_path */
-PHPAPI int _php_stream_stat_path(char *path, php_stream_statbuf *ssb TSRMLS_DC)
+PHPAPI int _php_stream_stat_path(char *path, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
php_stream_wrapper *wrapper = NULL;
char *path_to_open = path;
+ int ret;
+
+ /* Try to hit the cache first */
+ if (flags & PHP_STREAM_URL_STAT_LINK) {
+ if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) {
+ memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf));
+ return 0;
+ }
+ } else {
+ if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) {
+ memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf));
+ return 0;
+ }
+ }
wrapper = php_stream_locate_url_wrapper(path, &path_to_open, ENFORCE_SAFE_MODE TSRMLS_CC);
if (wrapper && wrapper->wops->url_stat) {
- return wrapper->wops->url_stat(wrapper, path_to_open, ssb TSRMLS_CC);
+ ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC);
+ if (ret == 0) {
+ /* Drop into cache */
+ if (flags & PHP_STREAM_URL_STAT_LINK) {
+ if (BG(CurrentLStatFile)) {
+ efree(BG(CurrentLStatFile));
+ }
+ BG(CurrentLStatFile) = estrdup(path);
+ memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf));
+ } else {
+ if (BG(CurrentStatFile)) {
+ efree(BG(CurrentStatFile));
+ }
+ BG(CurrentStatFile) = estrdup(path);
+ memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf));
+ }
+ }
+ return ret;
}
return -1;
}