FuncDoodle
Loading...
Searching...
No Matches
ExePath.h
Go to the documentation of this file.
1
18
19#pragma once
20
21#include <vector>
22
23// ChatGPT wrote this code :)
24// :(
25
26#ifdef _WIN32
27#include <windows.h>
28#elifdef __APPLE__
29#include <mach-o/dyld.h>
30#elifdef __linux__
31#include <unistd.h>
32#endif
33
34namespace ExePath {
41 inline const char* Get() {
42 static std::vector<char> buffer(1024);
43
44#ifdef _WIN32
45 GetModuleFileNameA(nullptr, buffer.data(), buffer.size());
46#elifdef __APPLE__
47 uint32_t size = buffer.size();
48 _NSGetExecutablePath(buffer.data(), &size);
49 buffer.resize(size);
50 _NSGetExecutablePath(buffer.data(), &size);
51#elifdef __linux__
52 ssize_t count =
53 readlink("/proc/self/exe", buffer.data(), buffer.size());
54 if (count != -1)
55 buffer.resize(count);
56#endif
57
58 return buffer.data();
59 }
60} // namespace ExePath
Definition ExePath.h:34
const char * Get()
Returns the full path to the currently running executable.
Definition ExePath.h:41