MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / GetRealPathUtf8

Function GetRealPathUtf8

src/tools/PlatformIO.cpp:136–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136bool GetRealPathUtf8(const std::string& fileName, std::string* realPath) {
137#ifdef _WIN32
138 if (realPath == nullptr) {
139 return false;
140 }
141
142 const std::wstring wideFileName = internal::WideFromUtf8(fileName);
143 HANDLE handle =
144 CreateFileW(wideFileName.c_str(), 0,
145 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
146 nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
147 if (handle == INVALID_HANDLE_VALUE) {
148 return false;
149 }
150
151 const DWORD flags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS;
152 const DWORD required = GetFinalPathNameByHandleW(handle, nullptr, 0, flags);
153 if (required == 0) {
154 CloseHandle(handle);
155 return false;
156 }
157 std::wstring resolved(static_cast<size_t>(required) + 1, L'\0');
158 const DWORD copied =
159 GetFinalPathNameByHandleW(handle, &resolved[0],
160 static_cast<DWORD>(resolved.size()), flags);
161 CloseHandle(handle);
162 if (copied == 0 || copied >= resolved.size()) {
163 return false;
164 }
165 resolved.resize(copied);
166 *realPath = internal::Utf8FromWide(resolved);
167 return true;
168#else
169 if (realPath == nullptr) {
170 return false;
171 }
172 char* resolved = realpath(fileName.c_str(), nullptr);
173 if (resolved == nullptr) {
174 return false;
175 }
176 *realPath = resolved;
177 std::free(resolved);
178 return true;
179#endif
180}
181
182bool HasMultipleLinksUtf8(const std::string& fileName) {
183#ifdef _WIN32

Callers 1

ConvertFileFunction · 0.85

Calls 4

Utf8FromWideFunction · 0.85
WideFromUtf8Function · 0.50
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected