diff options
Diffstat (limited to 'libcommon/tempfile.cpp')
-rw-r--r-- | libcommon/tempfile.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp index 5d3a086..c30bb57 100644 --- a/libcommon/tempfile.cpp +++ b/libcommon/tempfile.cpp @@ -1,5 +1,9 @@ #include "tempfile.h" +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include <iostream> namespace fs = std::filesystem; @@ -12,7 +16,12 @@ fs::path Tempfile::GetPath() const Tempfile::Tempfile() { try { - m_path = std::string{tmpnam(NULL)} + ".zip"s; + char name[] = "/tmp/tempfileXXXXXX.zip"; + int fd = mkstemps(name, 4); + if (fd == -1) + std::runtime_error("mkstemps: "s + strerror(errno)); + close(fd); + m_path = std::string{name}; } catch (const std::exception& ex) { throw std::runtime_error("Tempfile error: "s + ex.what()); } |