From 14628f1c5dec3401043109a3d682cb462553cd88 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 3 Oct 2018 21:17:52 +0200 Subject: Add compatibility bit readlink in PHP doesn't error on regular files. --- win32/ioutil.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'win32/ioutil.c') diff --git a/win32/ioutil.c b/win32/ioutil.c index 0ca01261a5..5d729da081 100644 --- a/win32/ioutil.c +++ b/win32/ioutil.c @@ -1109,6 +1109,34 @@ PW32IO ssize_t php_win32_ioutil_readlink_w(const wchar_t *path, wchar_t *buf, si ret = php_win32_ioutil_readlink_int(h, buf, buf_len); + if (ret < 0) { + /* BC */ + wchar_t target[PHP_WIN32_IOUTIL_MAXPATHLEN]; + size_t offset = 0, + target_len = GetFinalPathNameByHandleW(h, target, PHP_WIN32_IOUTIL_MAXPATHLEN, VOLUME_NAME_DOS); + + if(target_len >= buf_len || target_len >= PHP_WIN32_IOUTIL_MAXPATHLEN || target_len == 0) { + CloseHandle(h); + return -1; + } + + if(target_len > 4) { + /* Skip first 4 characters if they are "\\?\" */ + if(target[0] == L'\\' && target[1] == L'\\' && target[2] == L'?' && target[3] == L'\\') { + offset = 4; + + /* \\?\UNC\ */ + if (target_len > 7 && target[4] == L'U' && target[5] == L'N' && target[6] == L'C') { + offset += 2; + target[offset] = L'\\'; + } + } + } + + ret = target_len - offset; + memcpy(buf, target + offset, (ret + 1)*sizeof(wchar_t)); + } + CloseHandle(h); return ret; -- cgit v1.2.1