6 #include <oftmpstream.hxx>
10 void fdoutbuf::set_fd(int _fd) {
14 int fdoutbuf::overflow (int_type c) {
20 if (write (fd, &z, 1) != 1) {
26 // write multiple characters
27 std::streamsize fdoutbuf::xsputn (const char* s,
28 std::streamsize num) {
32 return write(fd,s,num);
36 oftmpstream::oftmpstream () : ostream(0) {
42 oftmpstream::oftmpstream (const char *name) : ostream(0) {
50 oftmpstream::~oftmpstream () {
54 void oftmpstream::open (const char *name)
60 tmpname=string(name)+".XXXXXX";
62 char* chbuf=new char[tmpname.size()+1];
63 tmpname.copy(chbuf,tmpname.size()+1);
64 chbuf[tmpname.size()]=0;
71 string err="error creating temporary file "+tmpname;
74 throw ios_base::failure(err);
81 void oftmpstream::close()
87 fchmod (fd, 0644); // fix mkstemp permissions
90 if (rename (tmpname.c_str(), realname.c_str()) != 0)
92 string err="error renaming temporary file "+tmpname;
96 throw ios_base::failure(err);