Fix get_app_path() impl for Linux and Mac OS X

This commit is contained in:
David Capello 2013-11-25 10:42:08 -03:00
parent 866c770d89
commit 83ba85ff09

View File

@ -9,6 +9,15 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdexcept>
#include <vector>
#if __APPLE__
#include <mach-o/dyld.h>
#endif
#include "base/path.h"
#define MAXPATHLEN 1024
namespace base {
@ -44,7 +53,22 @@ void remove_directory(const string& path)
string get_app_path()
{
return getexecname();
std::vector<char> path(MAXPATHLEN);
#if __APPLE__
uint32_t size = path.size();
while (_NSGetExecutablePath(&path[0], &size) == -1)
path.resize(size);
#else
if (readlink("/proc/self/exe", &path[0], path.size()) > 0)
return std::string(&path[0]);
#endif
return std::string();
}
string get_temp_path()