Browse Source

[corlib] Add underlying Console stream specialization to FileStream

Marek Safar 10 years ago
parent
commit
ce89d264dc
2 changed files with 8 additions and 11 deletions
  1. 6 7
      mcs/class/corlib/System.IO/FileStream.cs
  2. 2 4
      mcs/class/corlib/System/Console.cs

+ 6 - 7
mcs/class/corlib/System.IO/FileStream.cs

@@ -73,12 +73,12 @@ namespace System.IO
 			: this (handle, access, ownsHandle, bufferSize, isAsync, false) {}
 
 		[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
-		internal FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isZeroSize)
+		internal FileStream (IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isConsoleWrapper)
 		{
 			if (handle == MonoIO.InvalidHandle)
 				throw new ArgumentException ("handle", Locale.GetText ("Invalid."));
 
-			Init (new SafeFileHandle (handle, false), access, ownsHandle, bufferSize, isAsync, isZeroSize);
+			Init (new SafeFileHandle (handle, false), access, ownsHandle, bufferSize, isAsync, isConsoleWrapper);
 		}
 
 		// construct from filename
@@ -291,15 +291,14 @@ namespace System.IO
 			}
 		}
 
-		private void Init (SafeFileHandle safeHandle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isZeroSize)
+		private void Init (SafeFileHandle safeHandle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync, bool isConsoleWrapper)
 		{
-			if (safeHandle.IsInvalid)
+			if (!isConsoleWrapper && safeHandle.IsInvalid)
 				throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), "handle");
 			if (access < FileAccess.Read || access > FileAccess.ReadWrite)
 				throw new ArgumentOutOfRangeException ("access");
-// TODO: enable
-//			if (bufferSize <= 0)
-//				throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
+			if (!isConsoleWrapper && bufferSize <= 0)
+				throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
 
 			MonoIOError error;
 			MonoFileType ftype = MonoIO.GetFileType (safeHandle, out error);

+ 2 - 4
mcs/class/corlib/System/Console.cs

@@ -209,11 +209,9 @@ namespace System
 
 		private static Stream Open (IntPtr handle, FileAccess access, int bufferSize)
 		{
-			if (handle == IntPtr.Zero)
-				return Stream.Null;
-
 			try {
-				return new FileStream (handle, access, false, bufferSize, false, bufferSize == 0);
+				// TODO: Should use __ConsoleStream from reference sources
+				return new FileStream (handle, access, false, bufferSize, false, true);
 			} catch (IOException) {
 				return Stream.Null;
 			}