handle openflags in tmpfstream, test rdwr-file
authorGerd von Egidy <gerd.von.egidy@intra2net.com>
Wed, 10 Mar 2010 17:27:20 +0000 (18:27 +0100)
committerGerd von Egidy <gerd.von.egidy@intra2net.com>
Wed, 10 Mar 2010 17:27:20 +0000 (18:27 +0100)
libi2ncommon.kdevelop
src/tmpfstream_impl.hpp
test/test_tmpfstream.cpp

index c1dab30..83121ff 100644 (file)
       <used>false</used>
       <version>3</version>
       <includestyle>3</includestyle>
-      <root>/usr/lib/qt-3.3</root>
+      <root>/usr/lib64/qt-3.3</root>
       <designerintegration>EmbeddedKDevDesigner</designerintegration>
-      <qmake>/usr/lib/qt-3.3/bin/qmake</qmake>
-      <designer>/usr/lib/qt-3.3/bin/designer</designer>
+      <qmake>/usr/lib64/qt-3.3/bin/qmake</qmake>
+      <designer>/usr/lib64/qt-3.3/bin/designer</designer>
       <designerpluginpaths/>
     </qt>
   </kdevcppsupport>
index 1549b53..be4dceb 100644 (file)
 
 #include <string>
 #include <stdio.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <fcntl.h>
 
 #include <tmpfstream.hpp>
 #include <filefunc.hxx>
@@ -42,9 +46,17 @@ bool tmpfstreamTempl<Device,Tr,Alloc>::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;
 
index 123fe88..5180401 100644 (file)
@@ -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()