}
-oftmpstream::oftmpstream () : ostream(0) {
+oftmpstream::oftmpstream ()
+: ostream(0)
+, file_mode(0644)
+{
fd = -1;
rdbuf(&buf);
is_open = false;
}
-oftmpstream::oftmpstream (const std::string &name) : ostream(0) {
+oftmpstream::oftmpstream (const std::string &name)
+: ostream(0)
+, file_mode(0644)
+{
fd = -1;
rdbuf(&buf);
is_open = false;
realname = name;
tmpname=name+".XXXXXX";
-
+ file_mode= 0644;
+
char* chbuf=new char[tmpname.size()+1];
tmpname.copy(chbuf,tmpname.size()+1);
chbuf[tmpname.size()]=0;
return;
fsync(fd);
- fchmod (fd, 0644); // fix mkstemp permissions
+ fchmod (fd, file_mode); // fix/change mkstemp permissions
::close (fd);
if (rename (tmpname.c_str(), realname.c_str()) != 0)
fd = -1;
is_open = false;
+ file_mode= 0644;
}
+
+
+/**
+ * @brief set file mode for the final file.
+ * @param mode the fin al file mode.
+ *
+ * When called after open(), it determines the file mode which should
+ * be used for the resulting file.
+ */
+void oftmpstream::set_file_mode(int mode)
+{
+ file_mode= mode;
+} // eo oftmpstream::set_file_mode(int)
void close();
std::string get_filename();
std::string get_tmp_filename();
+ void set_file_mode(int mode);
private:
int fd;
fdoutbuf buf;
bool is_open;
+ int file_mode;
std::string tmpname;
std::string realname;