Merge pull request #2003 from esdrubal/seq_test_fix2
[mono.git] / mcs / class / corlib / System.IO / FileStream.cs
index 1ca519f5d64b3948945b1522afba491c174f4029..9de058fbb3a3a42800baa9f25b84bb13b948515a 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
@@ -113,7 +113,6 @@ namespace System.IO
                {
                }
 
-#if !NET_2_1
                public FileStream (SafeFileHandle handle, FileAccess access)
                        :this(handle, access, DefaultBufferSize, false)
                {
@@ -130,6 +129,7 @@ namespace System.IO
                        Init (handle, access, false, bufferSize, isAsync, false);
                }
 
+#if !MOBILE
                [MonoLimitation ("This ignores the rights parameter")]
                public FileStream (string path, FileMode mode,
                                   FileSystemRights rights, FileShare share,
@@ -148,6 +148,11 @@ namespace System.IO
                }
 #endif
 
+               internal FileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, string msgPath, bool bFromProxy, bool useLongPath = false, bool checkHost = false)
+                       : this (path, mode, access, share, bufferSize, false, options)
+               {
+               }
+
                internal FileStream (string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool isAsync, bool anonymous)
                        : this (path, mode, access, share, bufferSize, anonymous, isAsync ? FileOptions.Asynchronous : FileOptions.None)
                {
@@ -286,10 +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 (!isConsoleWrapper && safeHandle.IsInvalid)
+                               throw new ArgumentException(Environment.GetResourceString("Arg_InvalidHandle"), "handle");
                        if (access < FileAccess.Read || access > FileAccess.ReadWrite)
                                throw new ArgumentOutOfRangeException ("access");
+                       if (!isConsoleWrapper && bufferSize <= 0)
+                               throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
 
                        MonoIOError error;
                        MonoFileType ftype = MonoIO.GetFileType (safeHandle, out error);
@@ -406,10 +415,8 @@ namespace System.IO
                                return ret;
                        }
                        set {
-                               if(value < 0) {
-                                       throw new ArgumentOutOfRangeException("Attempt to set the position to a negative value");
-                               }
-                               
+                               if (value < 0) throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
+
                                Seek (value, SeekOrigin.Begin);
                        }
                }
@@ -692,7 +699,7 @@ namespace System.IO
                        result.BytesRead = -1;
                        result.Count = numBytes;
                        result.OriginalCount = numBytes;
-
+/*
                        if (buf_dirty) {
                                MemoryStream ms = new MemoryStream ();
                                FlushBuffer (ms);
@@ -703,7 +710,7 @@ namespace System.IO
                                array = ms.ToArray ();
                                numBytes = array.Length;
                        }
-
+*/
                        WriteDelegate w = WriteInternal;
                        return w.BeginInvoke (array, offset, numBytes, userCallback, stateObject);      
                }
@@ -983,7 +990,7 @@ namespace System.IO
                        
                        if (count > 0) {
                                // Use the fastest method, all range checks has been done
-                               Buffer.BlockCopyInternal (buf, buf_offset, dest, dest_offset, count);
+                               Buffer.InternalBlockCopy (buf, buf_offset, dest, dest_offset, count);
                                buf_offset += count;
                        }
                        
@@ -1012,20 +1019,21 @@ namespace System.IO
                        return(count);
                }
 
-               void FlushBuffer (Stream st)
+               void FlushBuffer ()
                {
                        if (buf_dirty) {
-                               MonoIOError error;
+//                             if (st == null) {
+                                       MonoIOError error;
 
-                               if (CanSeek == true && !isExposed) {
-                                       MonoIO.Seek (safeHandle, buf_start, SeekOrigin.Begin, out error);
+                                       if (CanSeek == true && !isExposed) {
+                                               MonoIO.Seek (safeHandle, buf_start, SeekOrigin.Begin, out error);
 
-                                       if (error != MonoIOError.ERROR_SUCCESS) {
-                                               // don't leak the path information for isolated storage
-                                               throw MonoIO.GetException (GetSecureFileName (name), error);
+                                               if (error != MonoIOError.ERROR_SUCCESS) {
+                                                       // don't leak the path information for isolated storage
+                                                       throw MonoIO.GetException (GetSecureFileName (name), error);
+                                               }
                                        }
-                               }
-                               if (st == null) {
+
                                        int wcount = buf_length;
                                        int offset = 0;
                                        while (wcount > 0){
@@ -1037,9 +1045,9 @@ namespace System.IO
                                                wcount -= n;
                                                offset += n;
                                        }
-                               } else {
-                                       st.Write (buf, 0, buf_length);
-                               }
+//                             } else {
+//                                     st.Write (buf, 0, buf_length);
+//                             }
                        }
 
                        buf_start += buf_offset;
@@ -1047,15 +1055,10 @@ namespace System.IO
                        buf_dirty = false;
                }
 
-               private void FlushBuffer ()
-               {
-                       FlushBuffer (null);
-               }
-
                private void FlushBufferIfDirty ()
                {
                        if (buf_dirty)
-                               FlushBuffer (null);
+                               FlushBuffer ();
                }
 
                private void RefillBuffer ()