diff options
author | Anatol Belski <ab@php.net> | 2018-10-03 18:56:08 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2018-10-03 18:56:55 +0200 |
commit | 91c905e83c338ef66da824be4f90c1d78d134507 (patch) | |
tree | 6095583ab22193f27d4837f53d1f4f5e5a5850d8 /Zend/zend_virtual_cwd.c | |
parent | 97481fccb9265df7e813f8c4e3f25d3a20651ce2 (diff) | |
download | php-git-91c905e83c338ef66da824be4f90c1d78d134507.tar.gz |
Refactor php_sys_readlink
Also move the implementation into win32 where it belongs
Diffstat (limited to 'Zend/zend_virtual_cwd.c')
-rw-r--r-- | Zend/zend_virtual_cwd.c | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 079fab3eb6..16734501ec 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -113,78 +113,6 @@ static cwd_state main_cwd_state; /* True global */ # define CWD_STATE_FREE_ERR(state) CWD_STATE_FREE(state) #endif -#ifdef ZEND_WIN32 -CWD_API ssize_t php_sys_readlink(const char *link, char *target, size_t target_len){ /* {{{ */ - HANDLE hFile; - wchar_t *linkw = php_win32_ioutil_any_to_w(link), targetw[MAXPATHLEN]; - size_t ret_len, targetw_len, offset = 0; - char *ret; - - if (!linkw) { - return -1; - } - - if (!target_len) { - free(linkw); - return -1; - } - - hFile = CreateFileW(linkw, // file to open - 0, // query possible attributes - PHP_WIN32_IOUTIL_DEFAULT_SHARE_MODE, - NULL, // default security - OPEN_EXISTING, // existing file only - FILE_FLAG_BACKUP_SEMANTICS, // normal file - NULL); // no attr. template - if( hFile == INVALID_HANDLE_VALUE) { - free(linkw); - return -1; - } - - /* Despite MSDN has documented it won't to, the length returned by - GetFinalPathNameByHandleA includes the length of the - null terminator. This behavior is at least reproducible - with VS2012 and earlier, and seems not to be fixed till - now. Thus, correcting target_len so it's suddenly don't - overflown. */ - targetw_len = GetFinalPathNameByHandleW(hFile, targetw, MAXPATHLEN, VOLUME_NAME_DOS); - if(targetw_len >= target_len || targetw_len >= MAXPATHLEN || targetw_len == 0) { - free(linkw); - CloseHandle(hFile); - return -1; - } - - if(targetw_len > 4) { - /* Skip first 4 characters if they are "\\?\" */ - if(targetw[0] == L'\\' && targetw[1] == L'\\' && targetw[2] == L'?' && targetw[3] == L'\\') { - offset = 4; - - /* \\?\UNC\ */ - if (targetw_len > 7 && targetw[4] == L'U' && targetw[5] == L'N' && targetw[6] == L'C') { - offset += 2; - targetw[offset] = L'\\'; - } - } - } - - ret = php_win32_ioutil_conv_w_to_any(targetw + offset, targetw_len - offset, &ret_len); - if (!ret || ret_len >= MAXPATHLEN) { - CloseHandle(hFile); - free(linkw); - free(ret); - return -1; - } - memcpy(target, ret, ret_len + 1); - - free(ret); - CloseHandle(hFile); - free(linkw); - - return (ssize_t)ret_len; -} -/* }}} */ -#endif - static int php_is_dir_ok(const cwd_state *state) /* {{{ */ { zend_stat_t buf; |