Skip to content

Commit

Permalink
Utility: implement Path::executableLocation() on FreeBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
clausecker authored and mosra committed Dec 10, 2023
1 parent d99afc1 commit be614b9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Corrade/Utility/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
#endif
#endif

/* For executableLocation() on FreeBSD */
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

/* Windows */
/** @todo remove the superfluous includes when mingw is fixed (otherwise causes undefined EXTERN_C error) */
#ifdef CORRADE_TARGET_WINDOWS
Expand Down Expand Up @@ -521,6 +527,18 @@ Containers::Optional<Containers::String> executableLocation() {
CORRADE_INTERNAL_ASSERT_OUTPUT(_NSGetExecutablePath(path.data(), &size) == 0);
return path;

/* FreeBSD */
#elif defined(__FreeBSD__)
/* Get path size, it's returned excluding the null terminator */
std::size_t size;
constexpr int mib[4]{CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
sysctl(mib, 4, nullptr, &size, nullptr, 0);

/* Allocate a string of proper size and retreive the path into it */
Containers::String path{NoInit, size}
sysctl(mib, 4, path.data(), &size, nullptr, 0);
return path;

/* Windows (not RT) */
#elif defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT)
/** @todo get rid of MAX_PATH */
Expand Down

0 comments on commit be614b9

Please sign in to comment.