| 1401 | } |
| 1402 | |
| 1403 | SC::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 |
nothing calls this directly
no test coverage detected