[Mono-bugs] [Bug 35975][Nor] New - System.IO.FileStream doesn't obey FileMode specifier
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
19 Dec 2002 22:52:33 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by jonpryor@vt.edu.
http://bugzilla.ximian.com/show_bug.cgi?id=35975
--- shadow/35975 Thu Dec 19 17:52:33 2002
+++ shadow/35975.tmp.10629 Thu Dec 19 17:52:33 2002
@@ -0,0 +1,65 @@
+Bug#: 35975
+Product: Mono/Class Libraries
+Version: unspecified
+OS: other
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: jonpryor@vt.edu
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.IO.FileStream doesn't obey FileMode specifier
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+System.IO.FileStream doesn't obey the FileMode specifier passed to the
+constructor. In particular, it doesn't append text properly.
+
+Consider the following sample code:
+
+ // appending to a file...
+ using System;
+ using System.IO;
+
+ class R {
+ public static void AppendText (string file, string message) {
+ byte[] b = new byte[message.Length+1];
+ for (int i = 0; i != message.Length; ++i)
+ b[i] = (byte) message[i];
+ b[message.Length] = (byte) '\n';
+
+ using (FileStream fs = new FileStream (file, FileMode.Append,
+ FileAccess.Write, FileShare.None)) {
+ fs.Write (b, 0, b.Length);
+ }
+ }
+
+ public static void Main () {
+ AppendText ("af.txt", "Hello, world!");
+ AppendText ("af.txt", "Hello, world! 2");
+ AppendText ("af.txt", "Hello, world! 3");
+ AppendText ("af.txt", "Hello, world! 4");
+ }
+ }
+
+When compiled and executed with mono/mcs, the contents of `af.txt' contain:
+ Hello, world! 4
+
+I would expect it to contain:
+ Hello, world!
+ Hello, world! 2
+ Hello, world! 3
+ Hello, world! 4
+i.e. actually append text to the file. ;-)
+
+The problem seems to be generated because the FileMode value is only used
+in the function call MonoIO.Open (line 89), but it isn't used to set the
+current position in the file (buf_offset) in InitBuffer() (line 448).