bindrv_newwriter
bindrv_newwriter |
Purpose
Synopsis
s_bindrvctx bindrv_newwriter(size_t (*dowrite)(const void *,size_t,size_t,void*), void *rctx);
Arguments
dowrite
|
Callback function to write data to the output stream
|
rctx
|
File descriptor to be passed as the last argument of
dowrite
|
Return value
The new context or
NULL in case of error.
Example
In the following example the file
"bindata is open using C-function
fopen and a writer is created based on the resulting file descriptor:
f=fopen("bindata", "w"); bdrv=bindrv_newwriter( (size_t (*)(const void *,size_t,size_t,void*))fwrite, f);
Further information
1. Each context created using this function must be released by a call to
bindrv_delete.
2. The
dowrite function is used by the writer whenever it needs to write data. The function receives as input a buffer, its size and, as the last argument, the pointer
rctx. The third argument is always 1. The return value must be
1 if successful, any other value is interpreted as an error condition.
3. The required
dowrite routine has the same signature as the C-function
fwrite such that a BinDrv writer can use as input a file open with the C-function
fopen.
Related topics