]> granicus.if.org Git - php/commitdiff
Add compatibility bit
authorAnatol Belski <ab@php.net>
Wed, 3 Oct 2018 19:17:52 +0000 (21:17 +0200)
committerAnatol Belski <ab@php.net>
Wed, 3 Oct 2018 19:17:52 +0000 (21:17 +0200)
readlink in PHP doesn't error on regular files.

win32/ioutil.c

index 0ca01261a52cb6d2b88260c0a7fe85b8b039b51a..5d729da081131b5c887518d74c73e73ae86c33d1 100644 (file)
@@ -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;