1 // Copyright 2005 Ben Hutchings <ben@decadentplace.org.uk>.
2 // See the file "COPYING" for licence details.
4 #include "temp_file.hpp"
16 #include <glibmm/fileutils.h>
18 temp_file::temp_file(const std::string & base_name)
20 fd_ = Glib::file_open_tmp(name_, base_name);
23 // Workaround bug in glibc <2.2 that may cause the file to be
24 // created with lax permissions.
26 # if !__GLIBC_PREREQ(2, 2)
27 if (fchmod(fd_, S_IREAD|S_IWRITE) != 0 || ftruncate(fd_, 0) != 0)
30 throw std::runtime_error(std::strerror(errno));
36 temp_file::~temp_file()
42 // Don't assert that this is successful. The file could have
43 // been removed by another process.
44 unlink(name_.c_str());
48 void temp_file::close()
52 int result = ::close(fd_);
58 bool temp_file::keep_ = false;
60 void temp_file::keep_all(bool keep)