Initializing help system before first use

bindrv_newreader

bindrv_newreader


Purpose
Create a new BinDrv context for parsing an input stream.
Synopsis
s_bindrvctx bindrv_newreader(size_t (*doread)(void *,size_t,size_t,void*), void *rctx);
Arguments
doread 
Callback function to retrieve data from the input stream
rctx 
File descriptor to be passed as the last argument of doread
Return value
The new context or NULL in case of error.
Example
In the following example the file "bindata is opened using the C function fopen and a reader is created based on the resulting file descriptor:
f=fopen("bindata", "r");
bdrv=bindrv_newreader((size_t (*)(void *,size_t,size_t,void*))fread, f);
Further information
1. Each context created using this function must be released by a call to bindrv_delete.
2. The doread routine is used by the reader whenever it requires further data to process. The function receives as input a buffer (where read data has to be copied), its size and, as the last argument, the pointer rctx. The third argument of doread is always 1. The return value must be 1 if successful ( i.e. the requested amount of data has been read), any other value is interpreted as an error condition.
3. The required doread function has the same signature as the C function fread such that a BinDrv reader can use as input a file opened with the C function fopen.
Related topics