mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +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;
|
||||
} else {
|
||||
wchar_t cur_path[MAXPATHLEN+1];
|
||||
DWORD len = sizeof(cur_path);
|
||||
wchar_t *tmp = cur_path;
|
||||
|
||||
while(1) {
|
||||
DWORD r = GetCurrentDirectoryW(len, tmp);
|
||||
if (r < len) {
|
||||
if (tmp[1] == L':') {
|
||||
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';
|
||||
}
|
||||
if (NULL != _wgetcwd(cur_path, sizeof(cur_path)/sizeof(wchar_t))) {
|
||||
if (cur_path[1] == L':') {
|
||||
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 = -1;
|
||||
buf->st_dev = buf->st_rdev = pathw[0] - L'a';
|
||||
}
|
||||
break;
|
||||
} else if (!r) {
|
||||
buf->st_dev = buf->st_rdev = -1;
|
||||
break;
|
||||
} else {
|
||||
len = r+1;
|
||||
tmp = (wchar_t*)malloc(len*sizeof(wchar_t));
|
||||
buf->st_dev = buf->st_rdev = -1;
|
||||
}
|
||||
}
|
||||
if (tmp != cur_path) {
|
||||
free(tmp);
|
||||
} else {
|
||||
buf->st_dev = buf->st_rdev = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue