#include "config.h"
#include "GLibUtilities.h"
#if OS(WINDOWS)
#include <windows.h>
#include <wtf/text/WTFString.h>
#else
#include <limits.h>
#include <unistd.h>
#endif
#if OS(LINUX)
CString getCurrentExecutablePath()
{
static char readLinkBuffer[PATH_MAX];
ssize_t result = readlink("/proc/self/exe", readLinkBuffer, PATH_MAX);
if (result == -1)
return CString();
return CString(readLinkBuffer, result);
}
#elif OS(HURD)
CString getCurrentExecutablePath()
{
return CString();
}
#elif OS(UNIX)
CString getCurrentExecutablePath()
{
static char readLinkBuffer[PATH_MAX];
ssize_t result = readlink("/proc/curproc/file", readLinkBuffer, PATH_MAX);
if (result == -1)
return CString();
return CString(readLinkBuffer, result);
}
#elif OS(WINDOWS)
CString getCurrentExecutablePath()
{
static WCHAR buffer[MAX_PATH];
DWORD length = GetModuleFileNameW(0, buffer, MAX_PATH);
if (!length || (length == MAX_PATH && GetLastError() == ERROR_INSUFFICIENT_BUFFER))
return CString();
String path(buffer, length);
return path.utf8();
}
#endif