From 1d0fe1ab28b3f1453a221e9d554203d712962b18 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 7 Sep 2024 13:24:30 +0200 Subject: [PATCH] Port: Include some important changes of the OpenBSD port Forum thread: https://forum.freecad.org/viewtopic.php?t=80792 --- src/3rdParty/libE57Format/src/CheckedFile.cpp | 6 ++- src/App/Application.cpp | 41 ++++++++++++++++++- src/Mod/MeshPart/App/CMakeLists.txt | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/3rdParty/libE57Format/src/CheckedFile.cpp b/src/3rdParty/libE57Format/src/CheckedFile.cpp index 17f646d0a9..0822ae7c96 100644 --- a/src/3rdParty/libE57Format/src/CheckedFile.cpp +++ b/src/3rdParty/libE57Format/src/CheckedFile.cpp @@ -44,6 +44,10 @@ #include #include #include +#elif defined(__OpenBSD__) +#include +#include +#include #elif defined( __APPLE__ ) #include #include @@ -483,7 +487,7 @@ uint64_t CheckedFile::lseek64( int64_t offset, int whence ) #endif #elif defined( __linux__ ) int64_t result = ::lseek64( fd_, offset, whence ); -#elif defined( __APPLE__ ) +#elif defined( __APPLE__ ) || defined(__OpenBSD__) int64_t result = ::lseek( fd_, offset, whence ); #else #error "no supported OS platform defined" diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 2f65d4934e..c7e1f6ac3f 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -3323,7 +3323,46 @@ void Application::ExtractUserPath() mConfig["UserMacroPath"] = Base::FileInfo::pathToString(macro) + PATHSEP; } -#if defined (FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_BSD) +// TODO: Consider using this for all UNIX-like OSes +#if defined(__OpenBSD__) +#include +#include +#include +#include + +std::string Application::FindHomePath(const char* sCall) +{ + // We have three ways to start this application either use one of the two executables or + // import the FreeCAD.so module from a running Python session. In the latter case the + // Python interpreter is already initialized. + std::string absPath; + std::string homePath; + if (Py_IsInitialized()) { + // Note: realpath is known to cause a buffer overflow because it + // expands the given path to an absolute path of unknown length. + // Even setting PATH_MAX does not necessarily solve the problem + // for sure but the risk of overflow is rather small. + char resolved[PATH_MAX]; + char* path = realpath(sCall, resolved); + if (path) + absPath = path; + } + else { + int argc = 1; + QCoreApplication app(argc, (char**)(&sCall)); + absPath = QCoreApplication::applicationFilePath().toStdString(); + } + + // should be an absolute path now + std::string::size_type pos = absPath.find_last_of("/"); + homePath.assign(absPath,0,pos); + pos = homePath.find_last_of("/"); + homePath.assign(homePath,0,pos+1); + + return homePath; +} + +#elif defined (FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_BSD) #include #include #include diff --git a/src/Mod/MeshPart/App/CMakeLists.txt b/src/Mod/MeshPart/App/CMakeLists.txt index 11a84e1a13..d78fc8a197 100644 --- a/src/Mod/MeshPart/App/CMakeLists.txt +++ b/src/Mod/MeshPart/App/CMakeLists.txt @@ -19,6 +19,7 @@ include_directories( ${SMESH_INCLUDE_DIR} ${VTK_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR} + ${pybind11_INCLUDE_DIR} )