mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
rewrite the getcwd part
Also fixes a possible memory leak. Still not ideal, as seems CWD longer than MAX_PATH is still not supported. But a heap allocation is not needed anyway, as MAXPATHLEN value is the maximum supported.
This commit is contained in:
parent
7020e6f9ae
commit
ac82a34185
1 changed files with 8 additions and 21 deletions
|
@ -328,32 +328,19 @@ CWD_API int php_sys_stat_ex(const char *path, zend_stat_t *buf, int lstat) /* {{
|
||||||
buf->st_dev = buf->st_rdev = 0;
|
buf->st_dev = buf->st_rdev = 0;
|
||||||
} else {
|
} else {
|
||||||
wchar_t cur_path[MAXPATHLEN+1];
|
wchar_t cur_path[MAXPATHLEN+1];
|
||||||
DWORD len = sizeof(cur_path);
|
|
||||||
wchar_t *tmp = cur_path;
|
|
||||||
|
|
||||||
while(1) {
|
if (NULL != _wgetcwd(cur_path, sizeof(cur_path)/sizeof(wchar_t))) {
|
||||||
DWORD r = GetCurrentDirectoryW(len, tmp);
|
if (cur_path[1] == L':') {
|
||||||
if (r < len) {
|
if (pathw[0] >= L'A' && pathw[0] <= L'Z') {
|
||||||
if (tmp[1] == L':') {
|
buf->st_dev = buf->st_rdev = pathw[0] - L'A';
|
||||||
if (pathw[0] >= L'A' && pathw[0] <= L'Z') {
|
|
||||||
buf->st_dev = buf->st_rdev = pathw[0] - L'A';
|
|
||||||
} else {
|
|
||||||
buf->st_dev = buf->st_rdev = pathw[0] - L'a';
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
buf->st_dev = buf->st_rdev = -1;
|
buf->st_dev = buf->st_rdev = pathw[0] - L'a';
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
} else if (!r) {
|
|
||||||
buf->st_dev = buf->st_rdev = -1;
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
len = r+1;
|
buf->st_dev = buf->st_rdev = -1;
|
||||||
tmp = (wchar_t*)malloc(len*sizeof(wchar_t));
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
if (tmp != cur_path) {
|
buf->st_dev = buf->st_rdev = -1;
|
||||||
free(tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue