Created
August 21, 2021 13:43
-
-
Save ryutorion/24520f6e503cb3ec093eb0820b83be87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if _WINDOWS | |
#define WIN32_LEAN_AND_MEAN | |
#include <iostream> | |
#include <Windows.h> | |
int main(int argc, const char * argv[]) | |
{ | |
char path[MAX_PATH]; | |
GetModuleFileNameA(nullptr, path, sizeof(path)); | |
std::cout << path << std::endl; | |
} | |
#else | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <linux/limits.h> | |
int main() | |
{ | |
char tmp[PATH_MAX]; | |
auto result = readlink("/proc/self/exe", tmp, PATH_MAX); | |
tmp[result] = '\0'; | |
printf("%s\n", tmp); | |
char path[PATH_MAX] {}; | |
realpath(tmp, path); | |
printf("%s\n", path); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment