Skip to content
Snippets Groups Projects
Verified Commit 947ef878 authored by Lars Bilke's avatar Lars Bilke
Browse files

Refactor std::tmpnam to std::filesystem::temp_directory_path.

Requires gcc 8.
parent 2bc0235f
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,11 @@ target_link_libraries(ApplicationsFileIO ...@@ -32,6 +32,11 @@ target_link_libraries(ApplicationsFileIO
logog logog
PRIVATE MeshLib GitInfoLib) PRIVATE MeshLib GitInfoLib)
# std::filesystem is available on gcc 8 by linking to stdc++fs
if(COMPILER_IS_GCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9)
target_link_libraries(ApplicationsFileIO PUBLIC stdc++fs)
endif()
if(OGS_BUILD_GUI) if(OGS_BUILD_GUI)
# Needed for the XmlPrjInterface, which links the DE/Base/OGSError.h. # Needed for the XmlPrjInterface, which links the DE/Base/OGSError.h.
target_link_libraries(ApplicationsFileIO PUBLIC QtBase) target_link_libraries(ApplicationsFileIO PUBLIC QtBase)
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <cstdio> #include <cstdio>
#include <list> #include <list>
#include <memory> #include <memory>
#include <filesystem>
namespace fs = std::filesystem;
#include <logog/include/logog.hpp> #include <logog/include/logog.hpp>
...@@ -77,20 +79,18 @@ bool createSurface(GeoLib::Polyline const& ply, ...@@ -77,20 +79,18 @@ bool createSurface(GeoLib::Polyline const& ply,
0.0, 0, geo_names, false, false); 0.0, 0, geo_names, false, false);
gmsh_io.setPrecision(std::numeric_limits<double>::digits10); gmsh_io.setPrecision(std::numeric_limits<double>::digits10);
char file_base_name_c[L_tmpnam]; // fs::path const temp_dir = fs::temp_directory_path();
if (! std::tmpnam(file_base_name_c)) auto geo_file = fs::temp_directory_path() /= "createSurface.geo";
{ auto msh_file = fs::temp_directory_path() /= "createSurface.msh";
OGS_FATAL("Could not create unique file name.");
} gmsh_io.writeToFile(geo_file.string());
std::string const file_base_name(file_base_name_c);
gmsh_io.writeToFile(file_base_name + ".geo");
std::string gmsh_command =
gmsh_binary + " -2 -algo meshadapt \"" + file_base_name + ".geo\"";
gmsh_command += " -o \"" + file_base_name + ".msh\"";
// Newer gmsh versions write a newer file format for meshes per default. At // Newer gmsh versions write a newer file format for meshes per default. At
// the moment we can't read this new format. This is a switch for gmsh to // the moment we can't read this new format. This is a switch for gmsh to
// write the 'old' file format. // write the 'old' file format.
gmsh_command += " -format msh22"; std::string gmsh_command =
gmsh_binary + " -2 -algo meshadapt -format msh22 -o "
+ msh_file.string() + " " + geo_file.string();
int const gmsh_return_value = std::system(gmsh_command.c_str()); int const gmsh_return_value = std::system(gmsh_command.c_str());
if (gmsh_return_value != 0) if (gmsh_return_value != 0)
{ {
...@@ -98,18 +98,14 @@ bool createSurface(GeoLib::Polyline const& ply, ...@@ -98,18 +98,14 @@ bool createSurface(GeoLib::Polyline const& ply,
gmsh_return_value); gmsh_return_value);
} }
auto surface_mesh = auto surface_mesh =
FileIO::GMSH::readGMSHMesh("\"" + file_base_name + ".msh\""); FileIO::GMSH::readGMSHMesh(msh_file.string());
if (!surface_mesh) if (!surface_mesh)
{ {
WARN("The surface mesh could not be created."); WARN("The surface mesh could not be created.");
return false; return false;
} }
if (std::remove((file_base_name + ".geo").c_str()) !=0) if (!(fs::remove(geo_file) && fs::remove(msh_file)))
WARN("Could not remove temporary file '%s'.", WARN("Could not remove temporary files in createSurface.");
(file_base_name + ".geo").c_str());
if (std::remove((file_base_name + ".msh").c_str()) !=0)
WARN("Could not remove temporary file '%s'.",
(file_base_name + ".msh").c_str());
// convert the surface mesh into a geometric surface // convert the surface mesh into a geometric surface
if (!MeshLib::convertMeshToGeo(*surface_mesh, geometries, if (!MeshLib::convertMeshToGeo(*surface_mesh, geometries,
......
{ {
"minimum_version": { "minimum_version": {
"gcc": "7.3", "gcc": "8.0",
"clang": "3.5", "clang": "3.5",
"msvc": { "msvc": {
"year": "2017", "year": "2017",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment