2022-12-26 21:47:09 +00:00
|
|
|
#include "PathService.hpp"
|
2021-10-02 17:39:27 +01:00
|
|
|
|
2021-05-30 19:05:18 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <climits>
|
|
|
|
|
|
2021-10-02 17:39:27 +01:00
|
|
|
#include "src/Exceptions/Exception.hpp"
|
2021-05-30 19:05:18 +01:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace Services
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
2022-12-26 21:47:09 +00:00
|
|
|
std::string PathService::applicationDirPath() {
|
2022-02-05 15:32:08 +00:00
|
|
|
auto pathCharArray = std::array<char, PATH_MAX>();
|
2021-05-30 19:05:18 +01:00
|
|
|
|
2023-08-20 18:50:14 +01:00
|
|
|
if (::readlink("/proc/self/exe", pathCharArray.data(), PATH_MAX) < 0) {
|
2022-02-05 15:32:08 +00:00
|
|
|
throw Exceptions::Exception("Failed to obtain application directory path.");
|
|
|
|
|
}
|
2021-05-30 19:05:18 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
return std::filesystem::path(std::string(pathCharArray.begin(), pathCharArray.end())).parent_path();
|
2021-05-30 19:05:18 +01:00
|
|
|
}
|
|
|
|
|
}
|