add get_home_directory function

This commit is contained in:
hippoz 2022-07-28 19:08:41 +03:00
parent 0b287f755b
commit e413a7d69d
No known key found for this signature in database
GPG key ID: 7C52899193467641
3 changed files with 17 additions and 0 deletions

View file

@ -8,6 +8,7 @@ raven_dep = dependency('raven')
executable( executable(
'filemanager', 'filemanager',
'./src/Dirs.cpp',
'./src/FileButton.cpp', './src/FileButton.cpp',
'./src/DirectoryView.cpp', './src/DirectoryView.cpp',
'./src/TopBar.cpp', './src/TopBar.cpp',

11
src/Dirs.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "Dirs.hpp"
#include <cstdlib>
std::filesystem::path get_home_directory() {
auto home_env = std::getenv("HOME");
if (!home_env || !std::filesystem::exists(home_env)) {
return "/";
}
return home_env;
}

5
src/Dirs.hpp Normal file
View file

@ -0,0 +1,5 @@
#pragma once
#include <filesystem>
std::filesystem::path get_home_directory();