示例#1
0
        public void Seek(SafeFileHandle handle, long position, SeekOrigin origin)
        {
            var low  = (int)(position & 0xffffffff);
            var high = (int)(position >> 32);
            var f    = WinNative.SetFilePointer(handle, low, out high, WinNative.EMoveMethod.Begin);

            if (f == WinNative.INVALID_SET_FILE_POINTER)
            {
                throw new Win32Exception();
            }
        }
示例#2
0
        public void SetFileSize(SafeFileHandle handle, long count)
        {
            var low  = (int)(count & 0xffffffff);
            var high = (int)(count >> 32);

            WinNative.SetFilePointer(handle, low, out high, WinNative.EMoveMethod.Begin);
            if (!WinNative.SetEndOfFile(handle))
            {
                throw new Win32Exception();
            }

            FSync(handle);
        }
示例#3
0
        public static void Seek(SafeFileHandle handle, long position, SeekOrigin origin)
        {
#if !__MonoCS__ && !USE_UNIX_IO
            var low  = (int)(position & 0xffffffff);
            var high = (int)(position >> 32);
            var f    = WinNative.SetFilePointer(handle, low, out high, WinNative.EMoveMethod.Begin);
            if (f == WinNative.INVALID_SET_FILE_POINTER)
            {
                throw new Win32Exception();
            }
#else
            int r = 0;
            do
            {
                r = (int)Syscall.lseek(handle.DangerousGetHandle().ToInt32(), position, SeekFlags.SEEK_SET);
            } while (UnixMarshal.ShouldRetrySyscall(r));
            UnixMarshal.ThrowExceptionForLastErrorIf(r);
#endif
        }
示例#4
0
        public static void SetFileSize(SafeFileHandle handle, long count)
        {
#if !__MonoCS__ && !USE_UNIX_IO
            var low  = (int)(count & 0xffffffff);
            var high = (int)(count >> 32);
            WinNative.SetFilePointer(handle, low, out high, WinNative.EMoveMethod.Begin);
            if (!WinNative.SetEndOfFile(handle))
            {
                throw new Win32Exception();
            }
#else
            int r;
            do
            {
                r = Syscall.ftruncate(handle.DangerousGetHandle().ToInt32(), count);
            } while (UnixMarshal.ShouldRetrySyscall(r));
            UnixMarshal.ThrowExceptionForLastErrorIf(r);
#endif
            FSync(handle);
        }