From 5f0073b9e0ff11a0096abfccca3af4f51dd2a50d Mon Sep 17 00:00:00 2001 From: David Pello Date: Sat, 14 May 2016 20:30:19 +0200 Subject: [PATCH] BSD Porting fixes, conditional compilation and use of gettimeofday() --- src/3rdParty/salomesmesh/src/SMDS/SMDS_Mesh.cpp | 1 + src/App/Application.cpp | 16 +++++++++++++++- src/Base/TimeInfo.cpp | 9 ++++++--- src/Base/TimeInfo.h | 12 ++++++++++++ src/Main/MainPy.cpp | 6 +++--- src/Mod/Image/Gui/Command.cpp | 2 ++ src/Mod/Mesh/App/WildMagic4/Wm4System.cpp | 4 ++-- src/Mod/Spreadsheet/Gui/Command.cpp | 2 ++ 8 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/3rdParty/salomesmesh/src/SMDS/SMDS_Mesh.cpp b/src/3rdParty/salomesmesh/src/SMDS/SMDS_Mesh.cpp index 8b3cb7d53..d31934890 100644 --- a/src/3rdParty/salomesmesh/src/SMDS/SMDS_Mesh.cpp +++ b/src/3rdParty/salomesmesh/src/SMDS/SMDS_Mesh.cpp @@ -46,6 +46,7 @@ using namespace std; #if !(defined(__MACH__) && defined(__APPLE__)) #include #endif +#include #endif // number of added entitis to check memory after diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 6e52ba370..b2420e288 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -47,7 +47,10 @@ # include #endif - +#if defined(FC_OS_BSD) +#include +#include +#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 diff --git a/src/Base/TimeInfo.cpp b/src/Base/TimeInfo.cpp index 3c459a21e..99e707aa8 100644 --- a/src/Base/TimeInfo.cpp +++ b/src/Base/TimeInfo.cpp @@ -57,10 +57,13 @@ TimeInfo::~TimeInfo() void TimeInfo::setCurrent(void) { -#if defined (_MSC_VER) +#if defined (FC_OS_WIN32) _ftime( &timebuffer ); -#elif defined(__GNUC__) - ftime( &timebuffer ); +#else + struct timeval t; + gettimeofday(&t, NULL); + timebuffer.time = t.tv_sec; + timebuffer.millitm = t.tv_usec / 1000; #endif } diff --git a/src/Base/TimeInfo.h b/src/Base/TimeInfo.h index 7d73c5661..bdb75f9f7 100644 --- a/src/Base/TimeInfo.h +++ b/src/Base/TimeInfo.h @@ -28,13 +28,25 @@ #include +#if defined(FC_OS_WIN32) #include +#else +#include +#endif #include #ifdef __GNUC__ # include #endif +#if !defined(FC_OS_WIN32) +struct timeb +{ + int64_t time; + unsigned short millitm; +}; +#endif + namespace Base { /// BaseClass class and root of the type system diff --git a/src/Main/MainPy.cpp b/src/Main/MainPy.cpp index 0bec9afee..615dc8330 100644 --- a/src/Main/MainPy.cpp +++ b/src/Main/MainPy.cpp @@ -27,7 +27,7 @@ # undef _PreComp_ #endif -#ifdef FC_OS_LINUX +#ifdef FC_OS_LINUX || defined(FC_OS_BSD) # include #endif @@ -71,7 +71,7 @@ BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserv return true; } -#elif defined(FC_OS_LINUX) +#elif defined(FC_OS_LINUX) || defined(FC_OS_BSD) # ifndef GNU_SOURCE # define GNU_SOURCE # endif @@ -111,7 +111,7 @@ extern "C" argv[0] = (char*)malloc(MAX_PATH); strncpy(argv[0],szFileName,MAX_PATH); argv[0][MAX_PATH-1] = '\0'; // ensure null termination -#elif defined(FC_OS_LINUX) +#elif defined(FC_OS_LINUX) || defined(FC_OS_BSD) putenv("LANG=C"); putenv("LC_ALL=C"); // get whole path of the library diff --git a/src/Mod/Image/Gui/Command.cpp b/src/Mod/Image/Gui/Command.cpp index 6f2c819d5..593547b20 100644 --- a/src/Mod/Image/Gui/Command.cpp +++ b/src/Mod/Image/Gui/Command.cpp @@ -20,7 +20,9 @@ #endif #include +#if defined(FC_OS_WIN32) #include +#endif #include #include diff --git a/src/Mod/Mesh/App/WildMagic4/Wm4System.cpp b/src/Mod/Mesh/App/WildMagic4/Wm4System.cpp index 282662780..c68f78c95 100644 --- a/src/Mod/Mesh/App/WildMagic4/Wm4System.cpp +++ b/src/Mod/Mesh/App/WildMagic4/Wm4System.cpp @@ -22,7 +22,7 @@ using namespace Wm4; #include // support for GetTime -#ifdef __APPLE__ +#if !defined(WIN32) #include static timeval gs_kInitial; static bool gs_bInitializedTime = false; @@ -103,7 +103,7 @@ void System::EndianCopy (int iSize, int iQuantity, const void* pvSrc, //---------------------------------------------------------------------------- double System::GetTime () { -#ifdef __APPLE__ +#if !defined(WIN32) if (!gs_bInitializedTime) { gs_bInitializedTime = true; diff --git a/src/Mod/Spreadsheet/Gui/Command.cpp b/src/Mod/Spreadsheet/Gui/Command.cpp index 1a9d4bf8c..14cc3c9bc 100644 --- a/src/Mod/Spreadsheet/Gui/Command.cpp +++ b/src/Mod/Spreadsheet/Gui/Command.cpp @@ -21,7 +21,9 @@ #endif #include +#if defined(FC_OS_WIN32) #include +#endif #include #include