From 927e065f9829045247be7c0b3296408b6f577c1f Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Jun 2022 13:44:58 +0200 Subject: feat: add reading RLE files --- src/util/fs.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/util/fs.cpp (limited to 'src/util/fs.cpp') diff --git a/src/util/fs.cpp b/src/util/fs.cpp new file mode 100644 index 0000000..68c3dd9 --- /dev/null +++ b/src/util/fs.cpp @@ -0,0 +1,29 @@ +#include "fs.hpp" + +#include +#include +#include + +auto get_current_user_home_path() noexcept -> std::filesystem::path +{ + const auto *home_path_env = std::getenv("HOME"); + + if (home_path_env == nullptr) + { + return getpwuid(getuid())->pw_dir; + } + + return home_path_env; +} + +auto expand_path_home(const std::filesystem::path &path) noexcept -> std::filesystem::path +{ + const auto path_str = path.string(); + + if (!path_str.starts_with("~/")) + { + return path; + } + + return get_current_user_home_path() / std::filesystem::path(path_str.substr(2)); +} -- cgit v1.2.3-18-g5258