Functions that read from operating system streams, such as mco_db_load()
, must specify a stream reader function which has the following prototype:
typedef mco_size_sig_t(*mco_stream_read)(void* stream_handle, /*OUT*/void* to, mco_size_t max_nbytes);
Note that stream_handle can reference any legitimate stream (for example, a file or a socket) and to is a memory buffer of size max_nbytes.
An example of a stream reader implementation is the following:
mco_size_sig_t file_reader( void *stream_handle /* FILE * */, /* OUT */void *to, mco_size_t max_nbytes ) { FILE *f = (FILE *)stream_handle; mco_size_sig_t nbs; nbs = fread( to, 1, max_nbytes, f ); return nbs; }