libi2ncommon: (reinhard) added file mode support to oftmpstream.
authorReinhard Pfau <reinhard.pfau@intra2net.com>
Mon, 26 May 2008 10:03:44 +0000 (10:03 +0000)
committerReinhard Pfau <reinhard.pfau@intra2net.com>
Mon, 26 May 2008 10:03:44 +0000 (10:03 +0000)
src/oftmpstream.cpp
src/oftmpstream.hxx

index 66f3294..d847cd7 100644 (file)
@@ -34,13 +34,19 @@ std::streamsize fdoutbuf::xsputn (const char* s,
 }
 
 
-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;
@@ -69,7 +75,8 @@ void oftmpstream::open (const string &name)
 
     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;
@@ -95,7 +102,7 @@ void oftmpstream::close()
         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)
@@ -109,4 +116,18 @@ void oftmpstream::close()
 
     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)
index d2d005a..a6245d7 100644 (file)
@@ -26,10 +26,12 @@ public:
     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;