summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r--main/streams/plain_wrapper.c51
1 files changed, 18 insertions, 33 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 69c6a3ce2..1726e4f74 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -41,6 +41,7 @@
#include "php_streams_int.h"
#ifdef PHP_WIN32
# include "win32/winutil.h"
+# include "win32/time.h"
#endif
#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
@@ -1025,12 +1026,8 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, co
static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context TSRMLS_DC)
{
- char *p;
-
- if ((p = strstr(url, "://")) != NULL) {
- if (p < strchr(url, '/')) {
- url = p + 3;
- }
+ if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
+ url += sizeof("file://") - 1;
}
if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1 TSRMLS_CC)) {
@@ -1055,13 +1052,10 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *u
static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
- char *p;
int ret;
- if ((p = strstr(url, "://")) != NULL) {
- if (p < strchr(url, '/')) {
- url = p + 3;
- }
+ if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
+ url += sizeof("file://") - 1;
}
if (php_check_open_basedir(url TSRMLS_CC)) {
@@ -1084,7 +1078,6 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url,
static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC)
{
- char *p;
int ret;
if (!url_from || !url_to) {
@@ -1102,16 +1095,12 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
}
#endif
- if ((p = strstr(url_from, "://")) != NULL) {
- if (p < strchr(url_from, '/')) {
- url_from = p + 3;
- }
+ if (strncasecmp(url_from, "file://", sizeof("file://") - 1) == 0) {
+ url_from += sizeof("file://") - 1;
}
- if ((p = strstr(url_to, "://")) != NULL) {
- if (p < strchr(url_to, '/')) {
- url_to = p + 3;
- }
+ if (strncasecmp(url_to, "file://", sizeof("file://") - 1) == 0) {
+ url_to += sizeof("file://") - 1;
}
if (php_check_open_basedir(url_from TSRMLS_CC) || php_check_open_basedir(url_to TSRMLS_CC)) {
@@ -1176,10 +1165,8 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE;
char *p;
- if ((p = strstr(dir, "://")) != NULL) {
- if (p < strchr(dir, '/')) {
- dir = p + 3;
- }
+ if (strncasecmp(dir, "file://", sizeof("file://") - 1) == 0) {
+ dir += sizeof("file://") - 1;
}
if (!recursive) {
@@ -1261,15 +1248,16 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i
static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC)
{
-#if PHP_WIN32
- int url_len = strlen(url);
-#endif
+ if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
+ url += sizeof("file://") - 1;
+ }
+
if (php_check_open_basedir(url TSRMLS_CC)) {
return 0;
}
#if PHP_WIN32
- if (!php_win32_check_trailing_space(url, url_len)) {
+ if (!php_win32_check_trailing_space(url, (int)strlen(url))) {
php_error_docref1(NULL TSRMLS_CC, url, E_WARNING, "%s", strerror(ENOENT));
return 0;
}
@@ -1289,7 +1277,6 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i
static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC)
{
struct utimbuf *newtime;
- char *p;
#if !defined(WINDOWS) && !defined(NETWARE)
uid_t uid;
gid_t gid;
@@ -1307,10 +1294,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
}
#endif
- if ((p = strstr(url, "://")) != NULL) {
- if (p < strchr(url, '/')) {
- url = p + 3;
- }
+ if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
+ url += sizeof("file://") - 1;
}
if (php_check_open_basedir(url TSRMLS_CC)) {