From a8d51df78f86b00cee6951a93d269470d69080c1 Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Fri, 4 May 2018 22:00:43 -0400 Subject: [PATCH] use std::tmpfile instead of tmpnam --- source/gmsh/utilities.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/source/gmsh/utilities.cc b/source/gmsh/utilities.cc index 2f363bdc01..c020c77630 100644 --- a/source/gmsh/utilities.cc +++ b/source/gmsh/utilities.cc @@ -54,12 +54,16 @@ namespace Gmsh const AdditionalParameters &prm) { std::string base_name = prm.output_base_name; + FILE *tmp_file = nullptr; if (base_name == "") - base_name = std::tmpnam(nullptr); + { + tmp_file = std::tmpfile(); + AssertThrow(tmp_file != nullptr, ExcMessage("Creating temporary file failed!")); + } const std::string iges_file_name = base_name+".iges"; const std::string geo_file_name = base_name+".geo"; - const std::string msh_file_name = base_name+".msh"; + const std::string msh_file_name = base_name+".msh"; const std::string log_file_name = base_name+".log"; const std::string warnings_file_name = base_name+"_warn.log"; @@ -95,6 +99,10 @@ namespace Gmsh if (base_name != prm.output_base_name) { + // clean up if the filenames are temporary ones + AssertThrow(tmp_file != nullptr, ExcInternalError()); + const int ret = std::fclose(tmp_file); + AssertThrow(ret == 0, ExcInternalError()); { const auto ret_value = std::remove(iges_file_name.c_str()); AssertThrow(ret_value == 0, ExcMessage("Failed to remove "+iges_file_name)); -- 2.39.5