Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            unsafe
            {
                this.AssertNotDisposed();
                this.AssertValidBuffer(buffer, offset, count);
                if (!this.CanWrite)
                {
                    throw new NotSupportedException("File Stream does not support writing");
                }
                ulong num = (ulong)0;
                fixed(byte *numPointer = &buffer[offset])
                {
                    num = Stdlib.fwrite(numPointer, (ulong)1, (ulong)count, this.file);
                }

                if (num != (long)count)
                {
                    UnixMarshal.ThrowExceptionForLastError();
                }
                GC.KeepAlive(this);
            }
        }