Proper RUN_IN_PLACE support for OSX and FreeBSD

experimental
kwolekr 2012-12-05 21:41:05 -05:00 committed by Perttu Ahola
parent 6af8a34d91
commit 14657bd29a
1 changed files with 66 additions and 25 deletions

View File

@ -23,6 +23,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
See comments in porting.h
*/
#if defined(_WIN32)
#include <windows.h>
#elif defined(linux)
#include <unistd.h>
#elif defined(__APPLE__)
#include <unistd.h>
#include <mach-o/dyld.h>
#elif defined(__FreeBSD__)
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#include "porting.h"
#include "config.h"
#include "debug.h"
@ -166,7 +179,6 @@ void initializePaths()
Windows
*/
#if defined(_WIN32)
#include <windows.h>
const DWORD buflen = 1000;
char buf[buflen];
@ -191,7 +203,6 @@ void initializePaths()
Linux
*/
#elif defined(linux)
#include <unistd.h>
char buf[BUFSIZ];
memset(buf, 0, BUFSIZ);
@ -206,10 +217,43 @@ void initializePaths()
/*
OS X
*/
#elif defined(__APPLE__) || defined(__FreeBSD__)
#elif defined(__APPLE__)
//https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dyld.3.html
//TODO: Test this code
char buf[BUFSIZ];
uint32_t len = sizeof(buf);
assert(_NSGetExecutablePath(buf, &len) != 0);
pathRemoveFile(buf, '/');
path_share = std::string(buf) + "/..";
path_user = std::string(buf) + "/..";
/*
FreeBSD
*/
#elif defined(__FreeBSD__)
int mib[4];
char buf[BUFSIZ];
size_t len = sizeof(buf);
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
assert(sysctl(mib, 4, buf, &len, NULL, 0) != -1);
pathRemoveFile(buf, '/');
path_share = std::string(buf) + "/..";
path_user = std::string(buf) + "/..";
#else
//TODO: Get path of executable. This assumes working directory is bin/
dstream<<"WARNING: Relative path not properly supported on OS X and FreeBSD"
dstream<<"WARNING: Relative path not properly supported on this platform"
<<std::endl;
path_share = std::string("..");
path_user = std::string("..");
@ -228,7 +272,6 @@ void initializePaths()
Windows
*/
#if defined(_WIN32)
#include <windows.h>
const DWORD buflen = 1000;
char buf[buflen];
@ -251,7 +294,6 @@ void initializePaths()
Linux
*/
#elif defined(linux)
#include <unistd.h>
// Get path to executable
std::string bindir = "";
@ -296,7 +338,6 @@ void initializePaths()
OS X
*/
#elif defined(__APPLE__)
#include <unistd.h>
// Code based on
// http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c