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); }
public override long Seek(long offset, SeekOrigin origin) { AssertNotDisposed(); if (!CanSeek) { throw new NotSupportedException("The File Stream does not support seeking"); } Native.SeekFlags sf = Native.SeekFlags.SEEK_CUR; switch (origin) { case SeekOrigin.Begin: sf = Native.SeekFlags.SEEK_SET; break; case SeekOrigin.Current: sf = Native.SeekFlags.SEEK_CUR; break; case SeekOrigin.End: sf = Native.SeekFlags.SEEK_END; break; default: throw new ArgumentException("origin"); } int r = Native.Stdlib.fseek(file, offset, sf); if (r != 0) { throw new IOException("Unable to seek", UnixMarshal.CreateExceptionForLastError()); } long pos = Native.Stdlib.ftell(file); if (pos == -1) { throw new IOException("Unable to get current file position", UnixMarshal.CreateExceptionForLastError()); } GC.KeepAlive(this); return(pos); }
private static IntPtr Fopen(string path, string mode) { if (path.Length == 0) { throw new ArgumentException("path"); } if (mode == null) { throw new ArgumentNullException("mode"); } IntPtr f = Native.Stdlib.fopen(path, mode); if (f == IntPtr.Zero) { throw new DirectoryNotFoundException("path", UnixMarshal.CreateExceptionForLastError()); } return(f); }
public static void ThrowExceptionForLastError() { throw UnixMarshal.CreateExceptionForLastError(); }