From 770b29803cb96542a59b0dfff9181e3907623a0e Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 19 Oct 2006 09:49:44 +0000 Subject: Fixed mkdir("/tmp/foo//bar/log", 0777, true) --- main/streams/plain_wrapper.c | 30 +++++++++++++++++++++++++++--- main/win95nt.h | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) (limited to 'main') 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 -- cgit v1.2.1