Don't use path, use /proc. Here is some code i've written
const char* eif_ft__binary_file()
{
#ifdef OS_WINDOWS
wchar_t* p = (wchar_t*)malloc(282 * sizeof(wchar_t));
GetModuleFileNameW(NULL, p, 280);
char* res = transform__utf16_to_utf8(p,-1,NULL);
free(p);
return res;
#elif OS_LINUX
char* path = (char*)malloc(512);
int res = readlink("/proc/self/exe", path, 510);
if (res == -1) { free(path); return ""; }
path[res]=0;
TEMP_STRING_1 = path;
free(path);
return TEMP_STRING_1.text();
#elif OS_SOLARIS
char* path = (char*)malloc(512);
int res = readlink("/proc/self/path/a.out", path, 510);
if (res == -1) { free(path); return ""; }
path[res]=0;
TEMP_STRING_1 = path;
free(path);
return TEMP_STRING_1.text();
#elif OS_FREEBSD
char* path = (char*)malloc(512);
int res = readlink("/proc/curproc/file", path, 510);
if (res == -1) { free(path); return ""; }
path[res]=0;
TEMP_STRING_1 = path;
free(path);
return TEMP_STRING_1.text();
#else
TEMP_STRING_1 = "";
return TEMP_STRING_1.text();
#endif
}
TEMP_STRING ist just a generic macro for a String class.