MCPcopy Create free account
hub / github.com/Kitware/CMake / Realpath

Function Realpath

Source/kwsys/SystemTools.cxx:339–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337 return _wchdir(KWSYS_NAMESPACE::Encoding::ToWide(dir).c_str());
338}
339inline void Realpath(std::string const& path, std::string& resolved_path,
340 std::string* errorMessage = nullptr)
341{
342 std::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path);
343 wchar_t fullpath[MAX_PATH];
344 DWORD bufferLen = GetFullPathNameW(
345 tmp.c_str(), sizeof(fullpath) / sizeof(fullpath[0]), fullpath, nullptr);
346 if (bufferLen < sizeof(fullpath) / sizeof(fullpath[0])) {
347 resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath);
348 KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path);
349 } else if (errorMessage) {
350 if (bufferLen) {
351 *errorMessage = "Destination path buffer size too small.";
352 } else if (unsigned int errorId = GetLastError()) {
353 LPSTR message = nullptr;
354 DWORD size = FormatMessageA(
355 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
356 FORMAT_MESSAGE_IGNORE_INSERTS,
357 nullptr, errorId, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
358 (LPSTR)&message, 0, nullptr);
359 *errorMessage = std::string(message, size);
360 LocalFree(message);
361 } else {
362 *errorMessage = "Unknown error.";
363 }
364
365 resolved_path = "";
366 } else {
367 resolved_path = path;
368 }
369}
370#else
371# include <sys/types.h>
372

Callers 1

GetRealPathMethod · 0.85

Calls 2

realpathFunction · 0.85
c_strMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…