8 #include <oftmpstream.hxx>
12 void fdoutbuf::set_fd(int _fd) {
16 int fdoutbuf::overflow (int_type c) {
22 if (write (fd, &z, 1) != 1) {
28 // write multiple characters
29 std::streamsize fdoutbuf::xsputn (const char* s,
30 std::streamsize num) {
34 return write(fd,s,num);
38 oftmpstream::oftmpstream ()
47 oftmpstream::oftmpstream (const std::string &name)
58 oftmpstream::~oftmpstream () {
62 std::string oftmpstream::get_filename()
67 std::string oftmpstream::get_tmp_filename()
72 void oftmpstream::open (const string &name)
78 tmpname=name+".XXXXXX";
81 char* chbuf=new char[tmpname.size()+1];
82 tmpname.copy(chbuf,tmpname.size()+1);
83 chbuf[tmpname.size()]=0;
90 string err="error creating temporary file "+tmpname;
93 throw ios_base::failure(err);
100 void oftmpstream::close()
106 fchmod (fd, file_mode); // fix/change mkstemp permissions
109 if (rename (tmpname.c_str(), realname.c_str()) != 0)
111 string err="error renaming temporary file "+tmpname;
112 err+=" to "+realname;
114 err+=strerror(errno);
115 throw ios_base::failure(err);
125 * @brief set file mode for the final file.
126 * @param mode the fin al file mode.
128 * When called after open(), it determines the file mode which should
129 * be used for the resulting file.
131 void oftmpstream::set_file_mode(int mode)
134 } // eo oftmpstream::set_file_mode(int)