aboutsummaryrefslogtreecommitdiff
path: root/src/util/fs.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-12 13:44:58 +0200
committerHampusM <hampus@hampusmat.com>2022-06-13 17:57:01 +0200
commit927e065f9829045247be7c0b3296408b6f577c1f (patch)
tree7da3d9cd5aa4070414a8708a582f6c3ab3e1e708 /src/util/fs.cpp
parenteb66598c326862fd9dfc1899be4eac93f81a8023 (diff)
feat: add reading RLE files
Diffstat (limited to 'src/util/fs.cpp')
-rw-r--r--src/util/fs.cpp29
1 files changed, 29 insertions, 0 deletions
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 <cstdlib>
+#include <pwd.h>
+#include <unistd.h>
+
+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));
+}