MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / WindowsGetFileAttributes

Function WindowsGetFileAttributes

Source/utils/file_util.cpp:121–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119#if defined(_WIN64) || defined(_WIN32)
120namespace {
121DWORD WindowsGetFileAttributes(const char *path)
122{
123#if defined(NXDK)
124 const DWORD attr = ::GetFileAttributesA(path);
125#else
126 const auto pathUtf16 = ToWideChar(path);
127 if (pathUtf16 == nullptr) {
128 LogError("UTF-8 -> UTF-16 conversion error code {}", ::GetLastError());
129 return false;
130 }
131 const DWORD attr = ::GetFileAttributesW(&pathUtf16[0]);
132#endif
133 if (attr == INVALID_FILE_ATTRIBUTES) {
134 if (::GetLastError() == ERROR_FILE_NOT_FOUND || ::GetLastError() == ERROR_PATH_NOT_FOUND) {
135 ::SetLastError(ERROR_SUCCESS);
136 } else {
137#if defined(NXDK)
138 LogError("GetFileAttributesA: error code {}", ::GetLastError());
139#else
140 LogError("GetFileAttributesW: error code {}", ::GetLastError());
141#endif
142 }
143 }
144 return attr;
145}
146} // namespace
147
148#endif

Callers 2

DirectoryExistsFunction · 0.85
FileExistsAndIsWriteableFunction · 0.85

Calls 2

ToWideCharFunction · 0.85
LogErrorFunction · 0.85

Tested by

no test coverage detected