示例#1
0
 private void InitStream(IntPtr fileStream, bool ownsHandle)
 {
     if (StdioFileStream.InvalidFileStream == fileStream)
     {
         throw new ArgumentException(Locale.GetText("Invalid file stream"), "fileStream");
     }
     this.file  = fileStream;
     this.owner = ownsHandle;
     try
     {
         if ((long)Stdlib.fseek(this.file, (long)0, SeekFlags.SEEK_CUR) != (long)-1)
         {
             this.canSeek = true;
         }
         Stdlib.fread(IntPtr.Zero, (ulong)0, (ulong)0, this.file);
         if (Stdlib.ferror(this.file) == 0)
         {
             this.canRead = true;
         }
         Stdlib.fwrite(IntPtr.Zero, (ulong)0, (ulong)0, this.file);
         if (Stdlib.ferror(this.file) == 0)
         {
             this.canWrite = true;
         }
         Stdlib.clearerr(this.file);
     }
     catch (Exception exception)
     {
         throw new ArgumentException(Locale.GetText("Invalid file stream"), "fileStream");
     }
     GC.KeepAlive(this);
 }
示例#2
0
        public override int Read([In][Out] byte[] buffer, int offset, int count)
        {
            unsafe
            {
                this.AssertNotDisposed();
                this.AssertValidBuffer(buffer, offset, count);
                if (!this.CanRead)
                {
                    throw new NotSupportedException("Stream does not support reading");
                }
                ulong num = (ulong)0;
                fixed(byte *numPointer = &buffer[offset])
                {
                    num = Stdlib.fread(numPointer, (ulong)1, (ulong)count, this.file);
                }

                if (num != (long)count && Stdlib.ferror(this.file) != 0)
                {
                    throw new IOException();
                }
                GC.KeepAlive(this);
                return((int)num);
            }
        }