From: Gerd von Egidy Date: Wed, 10 Mar 2010 17:27:20 +0000 (+0100) Subject: handle openflags in tmpfstream, test rdwr-file X-Git-Tag: v2.6~112^2~9 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=fb2b9fa77dc7e03c6fa8d9bc5ef33803bc5d6843;p=libi2ncommon handle openflags in tmpfstream, test rdwr-file --- diff --git a/libi2ncommon.kdevelop b/libi2ncommon.kdevelop index c1dab30..83121ff 100644 --- a/libi2ncommon.kdevelop +++ b/libi2ncommon.kdevelop @@ -152,10 +152,10 @@ false 3 3 - /usr/lib/qt-3.3 + /usr/lib64/qt-3.3 EmbeddedKDevDesigner - /usr/lib/qt-3.3/bin/qmake - /usr/lib/qt-3.3/bin/designer + /usr/lib64/qt-3.3/bin/qmake + /usr/lib64/qt-3.3/bin/designer diff --git a/src/tmpfstream_impl.hpp b/src/tmpfstream_impl.hpp index 1549b53..be4dceb 100644 --- a/src/tmpfstream_impl.hpp +++ b/src/tmpfstream_impl.hpp @@ -19,9 +19,13 @@ #include #include + +#include +#include #include #include #include +#include #include #include @@ -42,9 +46,17 @@ bool tmpfstreamTempl::open(const std::string& tmpnametemplate, tmpnametemplate.copy(chbuf,tmpnametemplate.size()+1); chbuf[tmpnametemplate.size()]=0; - // TODO: flags handling + // always assume out-mode, otherwise the tmpfstream would be useless + int flags=0; + if (mode & std::ios_base::in) + flags |= O_RDWR; + else + flags |= O_WRONLY; + + if (mode & std::ios_base::app) + flags |= O_APPEND; - int fd=mkstemp(chbuf); + int fd=mkostemp(chbuf,flags); filename=chbuf; delete[] chbuf; diff --git a/test/test_tmpfstream.cpp b/test/test_tmpfstream.cpp index 123fe88..5180401 100644 --- a/test/test_tmpfstream.cpp +++ b/test/test_tmpfstream.cpp @@ -194,5 +194,21 @@ BOOST_AUTO_TEST_CASE(TmpofstreamMoveOverwrite) unlink(".foobar"); } +BOOST_AUTO_TEST_CASE(TmpfstreamReadWrite) +{ + tmpfstream tmpf("./tmp.XXXXXX",std::ios_base::out | std::ios_base::in ); + BOOST_CHECK_EQUAL( true, tmpf.is_open() ); + + tmpf << "hello world" << endl; + + tmpf.seekg(0); + string input; + getline(tmpf,input); + + BOOST_CHECK_EQUAL( "hello world", input ); + + tmpf.unlink(); + tmpf.close(); +} BOOST_AUTO_TEST_SUITE_END()