From 18235d3a6b1c79466ecc6ade84d747612aaa15fd Mon Sep 17 00:00:00 2001 From: Reinhard Pfau Date: Mon, 26 May 2008 10:03:44 +0000 Subject: [PATCH] libi2ncommon: (reinhard) added file mode support to oftmpstream. --- src/oftmpstream.cpp | 29 +++++++++++++++++++++++++---- src/oftmpstream.hxx | 2 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/oftmpstream.cpp b/src/oftmpstream.cpp index 66f3294..d847cd7 100644 --- a/src/oftmpstream.cpp +++ b/src/oftmpstream.cpp @@ -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) diff --git a/src/oftmpstream.hxx b/src/oftmpstream.hxx index d2d005a..a6245d7 100644 --- a/src/oftmpstream.hxx +++ b/src/oftmpstream.hxx @@ -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; -- 1.7.1