Пример #1
0
        /// <summary>
        /// Reads the requested data from the stream and writes it to the given address.
        /// </summary>
        static unsafe uint streamRead(IntPtr buffer, uint size, uint count, fi_handle handle)
        {
            Stream stream = handle.GetObject() as Stream;

            if ((stream == null) || (!stream.CanRead))
            {
                return(0);
            }
            uint  readCount = 0;
            byte *ptr       = (byte *)buffer;

            byte[] bufferTemp = new byte[size];
            int    read;

            while (readCount < count)
            {
                read = stream.Read(bufferTemp, 0, (int)size);
                if (read != (int)size)
                {
                    stream.Seek(-read, SeekOrigin.Current);
                    break;
                }
                for (int i = 0; i < read; i++, ptr++)
                {
                    *ptr = bufferTemp[i];
                }
                readCount++;
            }
            return((uint)readCount);
        }
Пример #2
0
        /// <summary>
        /// Reads the given data and writes it into the stream.
        /// </summary>
        static unsafe uint streamWrite(IntPtr buffer, uint size, uint count, fi_handle handle)
        {
            Stream stream = handle.GetObject() as Stream;

            if ((stream == null) || (!stream.CanWrite))
            {
                return(0);
            }
            uint writeCount = 0;

            byte[] bufferTemp = new byte[size];
            byte * ptr        = (byte *)buffer;

            while (writeCount < count)
            {
                for (int i = 0; i < size; i++, ptr++)
                {
                    bufferTemp[i] = *ptr;
                }
                try
                {
                    stream.Write(bufferTemp, 0, bufferTemp.Length);
                }
                catch
                {
                    return(writeCount);
                }
                writeCount++;
            }
            return(writeCount);
        }
Пример #3
0
        /// <summary>
        /// Returns the streams current position
        /// </summary>
        static int streamTell(fi_handle handle)
        {
            Stream stream = handle.GetObject() as Stream;

            if (stream == null)
            {
                return(-1);
            }
            return((int)stream.Position);
        }
Пример #4
0
        /// <summary>
        /// Moves the streams position.
        /// </summary>
        static int streamSeek(fi_handle handle, int offset, SeekOrigin origin)
        {
            Stream stream = handle.GetObject() as Stream;

            if (stream == null)
            {
                return(1);
            }
            stream.Seek((long)offset, origin);
            return(0);
        }