| 129 | } |
| 130 | |
| 131 | String realpath(const String &p_path) { |
| 132 | #ifdef WINDOWS_ENABLED |
| 133 | // Open file without read/write access |
| 134 | HANDLE hFile = ::CreateFileW((LPCWSTR)(p_path.utf16().get_data()), 0, |
| 135 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 136 | nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); |
| 137 | |
| 138 | if (hFile == INVALID_HANDLE_VALUE) { |
| 139 | return p_path; |
| 140 | } |
| 141 | |
| 142 | const DWORD expected_size = ::GetFinalPathNameByHandleW(hFile, nullptr, 0, FILE_NAME_NORMALIZED); |
| 143 | |
| 144 | if (expected_size == 0) { |
| 145 | ::CloseHandle(hFile); |
| 146 | return p_path; |
| 147 | } |
| 148 | |
| 149 | Char16String buffer; |
| 150 | buffer.resize_uninitialized((int)expected_size); |
| 151 | ::GetFinalPathNameByHandleW(hFile, (wchar_t *)buffer.ptrw(), expected_size, FILE_NAME_NORMALIZED); |
| 152 | |
| 153 | ::CloseHandle(hFile); |
| 154 | |
| 155 | String result = String::utf16(buffer.ptr()); |
| 156 | if (result.is_empty()) { |
| 157 | return p_path; |
| 158 | } |
| 159 | |
| 160 | return result.simplify_path(); |
| 161 | #elif defined(UNIX_ENABLED) |
| 162 | char *resolved_path = ::realpath(p_path.utf8().get_data(), nullptr); |
| 163 | |
| 164 | if (!resolved_path) { |
| 165 | return p_path; |
| 166 | } |
| 167 | |
| 168 | String result; |
| 169 | Error parse_ok = result.append_utf8(resolved_path); |
| 170 | ::free(resolved_path); |
| 171 | |
| 172 | if (parse_ok != OK) { |
| 173 | return p_path; |
| 174 | } |
| 175 | |
| 176 | return result.simplify_path(); |
| 177 | #endif |
| 178 | } |
| 179 | |
| 180 | String join(const String &p_a, const String &p_b) { |
| 181 | if (p_a.is_empty()) { |
no test coverage detected