Пример #1
0
        private static int GetPeriBase()
        {
            var fp = Stdlib.fopen(DeviceTreePath, DeviceTreeAccessMode);

            if (fp == IntPtr.Zero)
            {
                return(0);
            }

            var buf = new byte[4];

            // get peri base from device tree
            Stdlib.fseek(fp, 4, SeekFlags.SEEK_SET);

            var periBase = 0;

            if (Stdlib.fread(buf, 1, (ulong)buf.Length, fp) == (ulong)buf.Length)
            {
                periBase = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3] << 0;
            }

            Stdlib.fclose(fp);

            return(periBase);
        }
Пример #2
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);
 }
Пример #3
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);
        }