-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.cpp
36 lines (33 loc) · 821 Bytes
/
path.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "path.hpp"
#ifndef BFX_PATH
#define BFX_PATH
namespace path
{
fs::path getExecutablePath()
{
#if defined(_WIN32)
char rawPathName[MAX_PATH];
GetModuleFileNameA(NULL, rawPathName, MAX_PATH);
return fs::path(rawPathName);
#endif
#ifdef __linux__
char rawPathName[PATH_MAX];
realpath(PROC_SELF_EXE, rawPathName);
return fs::path(rawPathName);
#endif
#ifdef __APPLE__
char rawPathName[PATH_MAX];
char realPathName[PATH_MAX];
uint32_t rawPathSize = (uint32_t)sizeof(rawPathName);
if(!_NSGetExecutablePath(rawPathName, &rawPathSize)) {
realpath(rawPathName, realPathName);
}
return fs::path(realPathName);
#endif
}
fs::path getExecutableDir()
{
return getExecutablePath().parent_path();
}
}
#endif