BSD Porting fixes, conditional compilation and use of gettimeofday()

This commit is contained in:
David Pello
2016-05-14 20:30:19 +02:00
committed by wmayer
parent b5dfc41759
commit 5f0073b9e0
8 changed files with 43 additions and 9 deletions

View File

@@ -47,7 +47,10 @@
# include <Shlobj.h>
#endif
#if defined(FC_OS_BSD)
#include <sys/param.h>
#include <sys/sysctl.h>
#endif
#include "Application.h"
#include "Document.h"
@@ -2091,7 +2094,18 @@ std::string Application::FindHomePath(const char* sCall)
// path. In the worst case we simply get q wrong path and FreeCAD is not
// able to load its modules.
char resolved[PATH_MAX];
#if defined(FC_OS_BSD)
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
size_t cb = sizeof(resolved);
sysctl(mib, 4, resolved, &cb, NULL, 0);
int nchars = strlen(resolved);
#else
int nchars = readlink("/proc/self/exe", resolved, PATH_MAX);
#endif
if (nchars < 0 || nchars >= PATH_MAX)
throw Base::Exception("Cannot determine the absolute path of the executable");
resolved[nchars] = '\0'; // enfore null termination