#include "SDL_internal.h"
#include "SDL_appid.h"
#include <unistd.h>
const char *SDL_GetExeName(void)
{
static const char *proc_name = NULL;
if (!proc_name) {
#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_FREEBSD) || defined (SDL_PLATFORM_NETBSD) || defined(SDL_PLATFORM_HURD)
static char linkfile[1024];
int linksize;
#if defined(SDL_PLATFORM_LINUX) || defined(SDL_PLATFORM_HURD)
const char *proc_path = "/proc/self/exe";
#elif defined(SDL_PLATFORM_FREEBSD)
const char *proc_path = "/proc/curproc/file";
#elif defined(SDL_PLATFORM_NETBSD)
const char *proc_path = "/proc/curproc/exe";
#endif
linksize = readlink(proc_path, linkfile, sizeof(linkfile) - 1);
if (linksize > 0) {
linkfile[linksize] = '\0';
proc_name = SDL_strrchr(linkfile, '/');
if (proc_name) {
++proc_name;
} else {
proc_name = linkfile;
}
}
#endif
}
return proc_name;
}
const char *SDL_GetAppID(void)
{
const char *id_str = SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING);
if (!id_str) {
id_str = SDL_GetExeName();
}
if (!id_str) {
id_str = "SDL_App";
}
return id_str;
}