#include <stdio.h>

#ifdef __unix__
#include <unistd.h>
#endif  /* __unix__ */

#ifdef WIN32
#include <windows.h>
#endif  /* WIN32 */

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  /* __linux__ */

#ifdef __FreeBSD__
    const char *proc_path = "/proc/curproc/file";
    printf("This is a FreeBSD system, using %s\n", proc_path);
#endif  /* __FreeBSD__ */

    count = readlink(proc_path, path, 1023);
#endif  /* __unix__ */

#ifdef WIN32
    printf("This is a Windows system, using GetModuleFileName()\n");
    count = GetModuleFileName(0, path, 1023);
#endif  /* WIN32 */

    path[count] = 0;

    printf("executable path: %s\n", path);

    return 0;
}