2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
27 #include <oftmpstream.hxx>
31 void fdoutbuf::set_fd(int _fd) {
35 int fdoutbuf::overflow (int_type c) {
41 if (write (fd, &z, 1) != 1) {
47 // write multiple characters
48 std::streamsize fdoutbuf::xsputn (const char* s,
49 std::streamsize num) {
53 return write(fd,s,num);
57 oftmpstream::oftmpstream ()
66 oftmpstream::oftmpstream (const std::string &name)
77 oftmpstream::~oftmpstream () {
81 std::string oftmpstream::get_filename()
86 std::string oftmpstream::get_tmp_filename()
91 void oftmpstream::open (const string &name)
97 tmpname=name+".XXXXXX";
100 char* chbuf=new char[tmpname.size()+1];
101 tmpname.copy(chbuf,tmpname.size()+1);
102 chbuf[tmpname.size()]=0;
109 string err="error creating temporary file "+tmpname;
111 err+=strerror(errno);
112 throw ios_base::failure(err);
119 void oftmpstream::close()
124 fchmod (fd, file_mode); // fix/change mkstemp permissions
128 if (rename (tmpname.c_str(), realname.c_str()) != 0)
130 string err="error renaming temporary file "+tmpname;
131 err+=" to "+realname;
133 err+=strerror(errno);
134 throw ios_base::failure(err);
144 * @brief set file mode for the final file.
145 * @param mode the fin al file mode.
147 * When called after open(), it determines the file mode which should
148 * be used for the resulting file.
150 void oftmpstream::set_file_mode(int mode)
153 } // eo oftmpstream::set_file_mode(int)