[corlib] Add underlying Console stream specialization to FileStream
authorMarek Safar <marek.safar@gmail.com>
Wed, 19 Aug 2015 15:18:54 +0000 (17:18 +0200)
committerMarek Safar <marek.safar@gmail.com>
Wed, 19 Aug 2015 15:18:54 +0000 (17:18 +0200)
mcs/class/corlib/System.IO/FileStream.cs
mcs/class/corlib/System/Console.cs

index bec2722bfadafafdbb98d2b30f5c65a134c6237d..0c259783836fdaa71633a02ebc722a8ff8637f28 100644 (file)
@@ -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);
index aa714e08d2a10ef243dc590f1a4a06005732b285..99c5236a7ddf1a7f587168c4f624b3918b87e1a9 100644 (file)
@@ -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;
                        }