about summary refs log tree commit diff stats
path: root/src/global.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-11-26 14:05:29 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-11-26 14:05:29 -0500
commit2adce1795211fd0a42c3b4e03ab35a90bb01bccf (patch)
tree7fda2f874f0653e4c74edaaf1547fe9802b2005a /src/global.cpp
parent7fc0e0f50ae961efbe0cac1032b03a42d41d87d5 (diff)
downloadlingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.gz
lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.tar.bz2
lingo-ap-tracker-2adce1795211fd0a42c3b4e03ab35a90bb01bccf.zip
Stop relying on correctly set working directory
Diffstat (limited to 'src/global.cpp')
-rw-r--r--src/global.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/global.cpp b/src/global.cpp new file mode 100644 index 0000000..3ee4f58 --- /dev/null +++ b/src/global.cpp
@@ -0,0 +1,24 @@
1#include "global.h"
2
3#include <whereami.h>
4
5#include <filesystem>
6#include <string>
7#include <string_view>
8
9const std::filesystem::path& GetExecutableDirectory() {
10 static const std::filesystem::path* executable_directory = []() {
11 int length = wai_getExecutablePath(NULL, 0, NULL);
12 std::string buf(length, 0);
13 wai_getExecutablePath(buf.data(), length, NULL);
14
15 std::filesystem::path exec_path(buf);
16 return new std::filesystem::path(exec_path.parent_path());
17 }();
18
19 return *executable_directory;
20}
21
22std::string GetAbsolutePath(std::string_view path) {
23 return (GetExecutableDirectory() / path).string();
24}