diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-03 09:31:51 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-03 09:31:51 +0100 |
commit | 2b6f8123e925e3be8ce7c04eccdd49fc728314a5 (patch) | |
tree | 78e86bb428b3bc821ae84d0f6abe86136356bd1a /libcommon/tempfile.cpp | |
parent | 5581340f23b31114d33736c630de849898668f38 (diff) |
Separated out libcommon as libreichwein
Diffstat (limited to 'libcommon/tempfile.cpp')
-rw-r--r-- | libcommon/tempfile.cpp | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp deleted file mode 100644 index f425db2..0000000 --- a/libcommon/tempfile.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "tempfile.h" - -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <iostream> - -namespace fs = std::filesystem; -using namespace std::string_literals; - -fs::path Tempfile::GetPath() const -{ - return m_path; -} - -Tempfile::Tempfile(const std::filesystem::path& extension) -{ - try { - 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); - m_path = std::string{name}; - } catch (const std::exception& ex) { - throw std::runtime_error("Tempfile error: "s + ex.what()); - } -} - -Tempfile::~Tempfile() -{ - try { - fs::remove_all(m_path); - } catch (const std::exception& ex) { - std::cerr << "Warning: Couldn't remove temporary file " << m_path << std::endl; - } -} |