From fe554ee4aa208a52d80431ed1c1d741956f131e8 Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 1 Jun 2020 16:23:21 +0200 Subject: [PATCH] Fix own path detection on FreeBSD --- src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 1c6872f..a900939 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,8 @@ #include #elif __APPLE__ #include +#elif __FreeBSD__ + #include #endif @@ -26,7 +28,7 @@ static double get_scale(void) { } -static void get_exe_filename(char *buf, int sz) { +static void get_exe_filename(const char *self, char *buf, int sz) { #if _WIN32 int len = GetModuleFileName(NULL, buf, sz - 1); buf[len] = '\0'; @@ -38,6 +40,8 @@ static void get_exe_filename(char *buf, int sz) { #elif __APPLE__ unsigned size = sz; _NSGetExecutablePath(buf, &size); +#elif __FreeBSD__ + realpath(self, buf); #else strcpy(buf, "./lite"); #endif @@ -111,8 +115,13 @@ int main(int argc, char **argv) { lua_pushnumber(L, get_scale()); lua_setglobal(L, "SCALE"); +#ifdef __FreeBSD__ + char exename[PATH_MAX]; +#else char exename[2048]; - get_exe_filename(exename, sizeof(exename)); +#endif + + get_exe_filename(argv[0], exename, sizeof(exename)); lua_pushstring(L, exename); lua_setglobal(L, "EXEFILE");