Skip to content

Commit

Permalink
chore: GetApplicationDirectory definition for FreeBSD (#4318)
Browse files Browse the repository at this point in the history
  • Loading branch information
dostoievsky authored Sep 15, 2024
1 parent ed70267 commit d02fcc5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ unsigned int __stdcall timeBeginPeriod(unsigned int uPeriod);
unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
#elif defined(__linux__)
#include <unistd.h>
#elif defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
#elif defined(__APPLE__)
#include <sys/syslimits.h>
#include <mach-o/dyld.h>
Expand Down Expand Up @@ -2161,6 +2165,28 @@ const char *GetApplicationDirectory(void)
appDir[0] = '.';
appDir[1] = '/';
}
#elif defined(__FreeBSD__)
size_t size = sizeof(appDir);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};

if (sysctl(mib, 4, appDir, &size, NULL, 0) == 0)
{
int len = strlen(appDir);
for (int i = len; i >= 0; --i)
{
if (appDir[i] == '/')
{
appDir[i + 1] = '\0';
break;
}
}
}
else
{
appDir[0] = '.';
appDir[1] = '/';
}

#endif

return appDir;
Expand Down

0 comments on commit d02fcc5

Please sign in to comment.