+ 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);
+
+ if (error != MonoIOError.ERROR_SUCCESS) {
+ throw MonoIO.GetException (name, error);
+ }
+
+ if (ftype == MonoFileType.Unknown) {
+ throw new IOException ("Invalid handle.");
+ } else if (ftype == MonoFileType.Disk) {
+ this.canseek = true;
+ } else {
+ this.canseek = false;
+ }
+
+ this.safeHandle = safeHandle;
+ ExposeHandle ();
+ this.access = access;
+ this.owner = ownsHandle;
+ this.async = isAsync;
+ this.anonymous = false;
+
+ if (canseek) {
+ buf_start = MonoIO.Seek (safeHandle, 0, SeekOrigin.Current, out error);
+ if (error != MonoIOError.ERROR_SUCCESS) {
+ throw MonoIO.GetException (name, error);
+ }
+ }
+
+ /* Can't set append mode */
+ this.append_startpos=0;
+ }
+