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); }
public PosixFileHandler(string path, string mode) { FileHandle = Stdlib.fopen(path, mode); if (FileHandle == IntPtr.Zero) { Errno err = Stdlib.GetLastError(); throw new FileIOException(err, path); } }
private static bool FileExists(string file) { bool zero = false; IntPtr intPtr = Stdlib.fopen(file, "r"); zero = intPtr != IntPtr.Zero; if (intPtr != IntPtr.Zero) { Stdlib.fclose(intPtr); } return(zero); }
private static IntPtr Fopen(string path, string mode) { if (path == null) { throw new ArgumentNullException("path"); } if (path.Length == 0) { throw new ArgumentException("path"); } if (mode == null) { throw new ArgumentNullException("mode"); } IntPtr intPtr = Stdlib.fopen(path, mode); if (intPtr == IntPtr.Zero) { throw new DirectoryNotFoundException("path", UnixMarshal.CreateExceptionForLastError()); } return(intPtr); }