MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / realpath

Function realpath

modules/mono/utils/path_utils.cpp:131–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129}
130
131String 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
180String join(const String &p_a, const String &p_b) {
181 if (p_a.is_empty()) {

Callers 4

get_file_path_from_envFunction · 0.85
generate_cs_apiMethod · 0.85
get_real_pathMethod · 0.85
get_executable_pathMethod · 0.85

Calls 9

get_dataMethod · 0.45
utf16Method · 0.45
resize_uninitializedMethod · 0.45
ptrwMethod · 0.45
ptrMethod · 0.45
is_emptyMethod · 0.45
simplify_pathMethod · 0.45
utf8Method · 0.45
append_utf8Method · 0.45

Tested by

no test coverage detected