MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / getApplicationRootDirectory

Method getApplicationRootDirectory

Libraries/FileSystem/FileSystem.cpp:1403–1430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1401}
1402
1403SC::StringSpan SC::FileSystem::Operations::getApplicationRootDirectory(StringPath& applicationRootDirectory)
1404{
1405 StringSpan exeView = getExecutablePath(applicationRootDirectory);
1406 if (exeView.isEmpty())
1407 return {};
1408 // Find the last path separator (either '\\' or '/')
1409 ssize_t lastSeparator = -1;
1410 wchar_t* buffer = applicationRootDirectory.writableSpan().data();
1411 const size_t bufferLength = applicationRootDirectory.view().sizeInBytes() / sizeof(wchar_t);
1412 for (size_t i = 0; i < bufferLength; ++i)
1413 {
1414 if (buffer[i] == L'\\' || buffer[i] == L'/')
1415 lastSeparator = static_cast<ssize_t>(i);
1416 }
1417 if (lastSeparator < 0)
1418 {
1419 // No separator found, return empty
1420 (void)applicationRootDirectory.resize(0);
1421 ::memset(buffer, 0, StringPath::StorageCapacity * sizeof(wchar_t));
1422 return {};
1423 }
1424 const size_t copyLen = static_cast<size_t>(lastSeparator);
1425 buffer[copyLen] = 0;
1426 (void)applicationRootDirectory.resize(copyLen);
1427 // null terminate the path
1428 ::memset(buffer + copyLen + 1, 0, (StringPath::StorageCapacity - copyLen - 1) * sizeof(wchar_t));
1429 return applicationRootDirectory.view();
1430}
1431#else
1432
1433#include <dirent.h> // DIR, opendir, readdir, closedir

Callers

nothing calls this directly

Calls 9

getExecutablePathFunction · 0.85
dirnameFunction · 0.85
writableSpanMethod · 0.80
isEmptyMethod · 0.45
dataMethod · 0.45
sizeInBytesMethod · 0.45
viewMethod · 0.45
resizeMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected