The mi_stream_read() function

The mi_stream_read() function reads a specified number of bytes from a stream into a buffer.

Syntax

mi_integer mi_stream_read(strm_desc, buf, nbytes)
   MI_STREAM *strm_desc;
   void *buf;
   mi_integer nbytes;
strm_desc
A pointer to a stream descriptor for an open stream.
buf
A pointer to a user-allocated buffer.
nbytes
The maximum number of bytes to read into the buf buffer.
Valid in client LIBMI application? Valid in user-defined routine?
No Yes

Usage

The mi_stream_read() function reads up to nbytes bytes from the open stream that strm_desc references. The function copies this data into the buf user-defined buffer. The read operation begins at the current stream seek position. You can use mi_stream_tell() or mi_stream_getpos() to obtain this seek position.

To read to the end of the stream, call mi_stream_read() in a loop until it returns the MI_STREAM_EEOF constant, as follows:
  • For all calls except the last call, mi_stream_read() reads nbytes or fewer bytes and returns the number of bytes it has read.
  • For the last call, mi_stream_read() returns the MI_STREAM_EEOF constant to indicate that it has reached the end of the stream without any errors.

Return values

>=0
The number of bytes that the function has read from the open stream to the buf buffer.

The number of bytes read might be less than the nbytes value.

MI_STREAM_EEOF
The end of the stream has been reached without any errors.
MI_STREAM_EBADARG
The stream descriptor that strm_desc references is invalid, the buf user-defined buffer is invalid, or the specified nbytes value is less than zero.
MI_STREAM_ENIMPL
The stream class does not implement the stream-read function.
MI_ERROR
The function was not successful.