#include <stdio.h>
#ifdef __unix__
#include <unistd.h>
#endif
#ifdef WIN32
#include <windows.h>
#endif
int main(void) {
static char path[1024];
int count;
#ifdef __unix__
#ifdef __linux__
const char *proc_path = "/proc/self/exe";
printf("This is a Linux system, using %s\n", proc_path);
#endif
#ifdef __FreeBSD__
const char *proc_path = "/proc/curproc/file";
printf("This is a FreeBSD system, using %s\n", proc_path);
#endif
count = readlink(proc_path, path, 1023);
#endif
#ifdef WIN32
printf("This is a Windows system, using GetModuleFileName()\n");
count = GetModuleFileName(0, path, 1023);
#endif
path[count] = 0;
printf("executable path: %s\n", path);
return 0;
}