summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2006-10-19 09:49:44 +0000
committerDmitry Stogov <dmitry@php.net>2006-10-19 09:49:44 +0000
commit770b29803cb96542a59b0dfff9181e3907623a0e (patch)
tree77f4e117ae2463ea87a4d1d70c5b3a9256a7fa04 /main
parent76f23d4dcf8a3daed813def38271e62c47595a1c (diff)
downloadphp-git-770b29803cb96542a59b0dfff9181e3907623a0e.tar.gz
Fixed mkdir("/tmp/foo//bar/log", 0777, true)
Diffstat (limited to 'main')
-rw-r--r--main/streams/plain_wrapper.c30
-rw-r--r--main/win95nt.h2
2 files changed, 28 insertions, 4 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index f0c4f8436c..f61bde5c06 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1087,7 +1087,18 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
int offset = 0;
buf = estrndup(dir, dir_len);
+
+#ifdef PHP_WIN32
+ e = buf;
+ while (*e) {
+ if (*e == '/') {
+ *e = DEFAULT_SLASH;
+ }
+ e++;
+ }
+#else
e = buf + dir_len;
+#endif
if ((p = memchr(buf, DEFAULT_SLASH, dir_len))) {
offset = p - buf + 1;
@@ -1099,9 +1110,21 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
else {
/* find a top level directory we need to create */
while ( (p = strrchr(buf + offset, DEFAULT_SLASH)) || ( offset !=1 && (p = strrchr(buf, DEFAULT_SLASH))) ) {
+ int n = 0;
+
*p = '\0';
+ while (p > buf && *(p-1) == DEFAULT_SLASH) {
+ ++n;
+ --p;
+ *p = '\0';
+ }
if (VCWD_STAT(buf, &sb) == 0) {
- *p = DEFAULT_SLASH;
+ while (1) {
+ *p = DEFAULT_SLASH;
+ if (!n) break;
+ --n;
+ ++p;
+ }
break;
}
}
@@ -1115,9 +1138,10 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, char *dir, int mod
}
/* create any needed directories if the creation of the 1st directory worked */
while (++p != e) {
- if (*p == '\0' && *(p + 1) != '\0') {
+ if (*p == '\0') {
*p = DEFAULT_SLASH;
- if ((ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
+ if ((*(p+1) != '\0') &&
+ (ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
if (options & REPORT_ERRORS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
}
diff --git a/main/win95nt.h b/main/win95nt.h
index c5ed40fb09..de33a7ad80 100644
--- a/main/win95nt.h
+++ b/main/win95nt.h
@@ -41,7 +41,7 @@ typedef char * caddr_t;
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif
-#define chdir(path) SetCurrentDirectory(path)
+#define chdir(path) _chdir(path)
#define mkdir(a, b) _mkdir(a)
#define rmdir(a) _rmdir(a)
#define getpid _getpid