Fix proper readlink usage on Linux to get app path

This commit is contained in:
Wojtek Figat
2023-01-25 20:33:23 +01:00
parent e779c3ca17
commit 08ae1917e8

View File

@@ -2714,8 +2714,10 @@ Rectangle LinuxPlatform::GetVirtualDesktopBounds()
String LinuxPlatform::GetMainDirectory()
{
char buffer[UNIX_APP_BUFF_SIZE];
readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE);
const String str(buffer);
const int32 len = readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE);
if (len <= 0)
return String::Empty;
const String str(buffer, len);
int32 pos = str.FindLast(TEXT('/'));
if (pos != -1 && ++pos < str.Length())
return str.Left(pos);
@@ -2725,8 +2727,10 @@ String LinuxPlatform::GetMainDirectory()
String LinuxPlatform::GetExecutableFilePath()
{
char buffer[UNIX_APP_BUFF_SIZE];
readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE);
return String(buffer);
const int32 len = readlink("/proc/self/exe", buffer, UNIX_APP_BUFF_SIZE);
if (len <= 0)
return String::Empty;
return String(buffer, len);
}
Guid LinuxPlatform::GetUniqueDeviceId()