summaryrefslogtreecommitdiffhomepage
path: root/libcommon
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-12-20 16:52:47 +0100
committerRoland Reichwein <mail@reichwein.it>2020-12-20 16:52:47 +0100
commit73f0b597dec0705db01ed4eec7abaebc0295a243 (patch)
tree3599be15154a9eeaa09cb86e1918a13ac3a73bef /libcommon
parentef63da27938ae091a341893c38e59d489888625a (diff)
webserver 1.12: Added graphical statistics page (gnuplot generated)
Diffstat (limited to 'libcommon')
-rw-r--r--libcommon/tempfile.cpp14
-rw-r--r--libcommon/tempfile.h3
2 files changed, 12 insertions, 5 deletions
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) {
diff --git a/libcommon/tempfile.h b/libcommon/tempfile.h
index 5938fb9..b9839a7 100644
--- a/libcommon/tempfile.h
+++ b/libcommon/tempfile.h
@@ -9,7 +9,8 @@ class Tempfile
public:
std::filesystem::path GetPath() const;
- Tempfile();
+ // extension: e.g. ".zip"
+ Tempfile(const std::filesystem::path& extension = std::filesystem::path{});
~Tempfile();
};