Skip to content

Commit 14628f1

Browse files
committed
Add compatibility bit
readlink in PHP doesn't error on regular files.
1 parent 2ebac32 commit 14628f1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

win32/ioutil.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,34 @@ PW32IO ssize_t php_win32_ioutil_readlink_w(const wchar_t *path, wchar_t *buf, si
11091109

11101110
ret = php_win32_ioutil_readlink_int(h, buf, buf_len);
11111111

1112+
if (ret < 0) {
1113+
/* BC */
1114+
wchar_t target[PHP_WIN32_IOUTIL_MAXPATHLEN];
1115+
size_t offset = 0,
1116+
target_len = GetFinalPathNameByHandleW(h, target, PHP_WIN32_IOUTIL_MAXPATHLEN, VOLUME_NAME_DOS);
1117+
1118+
if(target_len >= buf_len || target_len >= PHP_WIN32_IOUTIL_MAXPATHLEN || target_len == 0) {
1119+
CloseHandle(h);
1120+
return -1;
1121+
}
1122+
1123+
if(target_len > 4) {
1124+
/* Skip first 4 characters if they are "\\?\" */
1125+
if(target[0] == L'\\' && target[1] == L'\\' && target[2] == L'?' && target[3] == L'\\') {
1126+
offset = 4;
1127+
1128+
/* \\?\UNC\ */
1129+
if (target_len > 7 && target[4] == L'U' && target[5] == L'N' && target[6] == L'C') {
1130+
offset += 2;
1131+
target[offset] = L'\\';
1132+
}
1133+
}
1134+
}
1135+
1136+
ret = target_len - offset;
1137+
memcpy(buf, target + offset, (ret + 1)*sizeof(wchar_t));
1138+
}
1139+
11121140
CloseHandle(h);
11131141

11141142
return ret;

0 commit comments

Comments
 (0)