From 73f0b597dec0705db01ed4eec7abaebc0295a243 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 20 Dec 2020 16:52:47 +0100 Subject: webserver 1.12: Added graphical statistics page (gnuplot generated) --- libcommon/tempfile.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'libcommon/tempfile.cpp') diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp index c30bb57..f425db2 100644 --- a/libcommon/tempfile.cpp +++ b/libcommon/tempfile.cpp @@ -14,10 +14,15 @@ fs::path Tempfile::GetPath() const return m_path; } -Tempfile::Tempfile() { +Tempfile::Tempfile(const std::filesystem::path& extension) +{ try { - char name[] = "/tmp/tempfileXXXXXX.zip"; - int fd = mkstemps(name, 4); + fs::path path { fs::temp_directory_path() / "tempfileXXXXXX"}; + if (!extension.empty()) + path += extension; + + fs::path::string_type name{path.native()}; + int fd = mkstemps(name.data(), extension.native().size()); if (fd == -1) std::runtime_error("mkstemps: "s + strerror(errno)); close(fd); @@ -27,7 +32,8 @@ Tempfile::Tempfile() { } } -Tempfile::~Tempfile() { +Tempfile::~Tempfile() +{ try { fs::remove_all(m_path); } catch (const std::exception& ex) { -- cgit v1.2.3