Exemple #1
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            this.AssertNotDisposed();
            if (!this.CanSeek)
            {
                throw new NotSupportedException("The File Stream does not support seeking");
            }
            SeekFlags seekFlag = SeekFlags.SEEK_CUR;

            switch (origin)
            {
            case SeekOrigin.Begin:
            {
                seekFlag = SeekFlags.SEEK_SET;
                break;
            }

            case SeekOrigin.Current:
            {
                seekFlag = SeekFlags.SEEK_CUR;
                break;
            }

            case SeekOrigin.End:
            {
                seekFlag = SeekFlags.SEEK_END;
                break;
            }

            default:
            {
                throw new ArgumentException("origin");
            }
            }
            if (Stdlib.fseek(this.file, offset, seekFlag) != 0)
            {
                throw new IOException("Unable to seek", UnixMarshal.CreateExceptionForLastError());
            }
            long num = Stdlib.ftell(this.file);

            if (num == (long)-1)
            {
                throw new IOException("Unable to get current file position", UnixMarshal.CreateExceptionForLastError());
            }
            GC.KeepAlive(this);
            return(num);
        }