Example #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);
        }
Example #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);
 }
Example #3
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);
            }
        }