implement finding kak executable path on MacOS

This commit is contained in:
Maxime Coste 2012-01-20 21:12:57 +00:00
parent bb36271ae5
commit 73ae3d292f

View File

@ -22,6 +22,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#if defined(__APPLE__)
#include <mach-o/dyld.h>
#endif
using namespace Kakoune; using namespace Kakoune;
using namespace std::placeholders; using namespace std::placeholders;
@ -628,7 +632,14 @@ void exec_commands_in_runtime_file(const CommandParameters& params,
const std::string& filename = params[0]; const std::string& filename = params[0];
char buffer[2048]; char buffer[2048];
#if defined(__linux__)
readlink("/proc/self/exe", buffer, 2048 - filename.length()); readlink("/proc/self/exe", buffer, 2048 - filename.length());
#elif defined(__APPLE__)
uint32_t bufsize = 2048 - filename.length();
_NSGetExecutablePath(buffer, &bufsize);
#else
# error "finding executable path is not implemented on this platform"
#endif
char* ptr = strrchr(buffer, '/'); char* ptr = strrchr(buffer, '/');
if (ptr) if (ptr)
{ {