MCPcopy Create free account
hub / github.com/OSGeo/PROJ / GetExecutableName

Function GetExecutableName

src/networkfilemanager.cpp:1540–1597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1538// ---------------------------------------------------------------------------
1539
1540static std::string GetExecutableName() {
1541#if defined(__linux)
1542 std::string path;
1543 path.resize(1024);
1544 const auto ret = readlink("/proc/self/exe", &path[0], path.size());
1545 if (ret > 0) {
1546 path.resize(ret);
1547 const auto pos = path.rfind('/');
1548 if (pos != std::string::npos) {
1549 path = path.substr(pos + 1);
1550 }
1551 return path;
1552 }
1553#elif defined(_WIN32)
1554 std::string path;
1555 path.resize(1024);
1556 if (GetModuleFileNameA(nullptr, &path[0],
1557 static_cast<DWORD>(path.size()))) {
1558 path.resize(strlen(path.c_str()));
1559 const auto pos = path.rfind('\\');
1560 if (pos != std::string::npos) {
1561 path = path.substr(pos + 1);
1562 }
1563 return path;
1564 }
1565#elif defined(__MACH__) && defined(__APPLE__)
1566 std::string path;
1567 path.resize(1024);
1568 uint32_t size = static_cast<uint32_t>(path.size());
1569 if (_NSGetExecutablePath(&path[0], &size) == 0) {
1570 path.resize(strlen(path.c_str()));
1571 const auto pos = path.rfind('/');
1572 if (pos != std::string::npos) {
1573 path = path.substr(pos + 1);
1574 }
1575 return path;
1576 }
1577#elif defined(__FreeBSD__)
1578 int mib[4];
1579 mib[0] = CTL_KERN;
1580 mib[1] = KERN_PROC;
1581 mib[2] = KERN_PROC_PATHNAME;
1582 mib[3] = -1;
1583 std::string path;
1584 path.resize(1024);
1585 size_t size = path.size();
1586 if (sysctl(mib, 4, &path[0], &size, nullptr, 0) == 0) {
1587 path.resize(strlen(path.c_str()));
1588 const auto pos = path.rfind('/');
1589 if (pos != std::string::npos) {
1590 path = path.substr(pos + 1);
1591 }
1592 return path;
1593 }
1594#endif
1595
1596 return std::string();
1597}

Callers 1

CurlFileHandleMethod · 0.85

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected