コード例 #1
0
        private bool Sys_Lseek()
        {
            // get fd index
            UInt64 fd_index = RBX;

            if (fd_index >= (UInt64)FDCount)
            {
                Terminate(ErrorCode.OutOfBounds); return(false);
            }

            // get fd
            IFileWrapper fd = FileDescriptors[fd_index];

            if (fd == null)
            {
                Terminate(ErrorCode.FDNotInUse); return(false);
            }

            // make sure it can seek
            if (!fd.CanSeek())
            {
                Terminate(ErrorCode.FilePermissions); return(false);
            }

            int        raw_mode = (int)RDX;
            SeekOrigin seek_origin;

            // process raw mode
            if (raw_mode == (int)SeekMode.set)
            {
                seek_origin = SeekOrigin.Begin;
            }
            else if (raw_mode == (int)SeekMode.cur)
            {
                seek_origin = SeekOrigin.Current;
            }
            else if (raw_mode == (int)SeekMode.end)
            {
                seek_origin = SeekOrigin.End;
            }
            // otherwise unknown seek mode - return -1
            else
            {
                RAX = ~(UInt64)0; return(true);
            }

            // attempt the seek
            try { RAX = (UInt64)fd.Seek((Int64)RCX, seek_origin); }
            catch (Exception) { RAX = ~(UInt64)0; }

            return(true);
        }