summaryrefslogtreecommitdiff
path: root/win32/ioutil.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2018-10-03 21:17:52 +0200
committerAnatol Belski <ab@php.net>2018-10-03 21:17:52 +0200
commit14628f1c5dec3401043109a3d682cb462553cd88 (patch)
tree608c78a15c16661e8f26c99f03a158104f5963e2 /win32/ioutil.c
parent2ebac3263ba8f2efcaab1f7ca37a652636582058 (diff)
downloadphp-git-14628f1c5dec3401043109a3d682cb462553cd88.tar.gz
Add compatibility bit
readlink in PHP doesn't error on regular files.
Diffstat (limited to 'win32/ioutil.c')
-rw-r--r--win32/ioutil.c28
1 files changed, 28 insertions, 0 deletions
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;