bfsetup() - buffered file setup
#include "bfile.h" int bfsetup(BFILE *bfp, int (*read)(size_t *nr, void *buf, size_t bsize, void *p), int (*write)(size_t *nw, void *buf, size_t bsize, void *p), int (*seek)(off_t *pos, void *p, off_t offset, int whence), int (*close)(void *p), void *p);
The bfsetup() function makes a BFILE object
refer to some underlying representation.
Where the underlying representation is an ordinary file, the function bfopen() can be used instead.
It is an error to use bfsetup()
on a BFILE object which has already been set
up with a previous call to bfsetup().
The functions passed to bfsetup() are passed the
parameter p every time they are called. Each must return
0 when they succeed or an errno value for failure. They are:
bsize bytes into buffer buf.
Store the number of bytes read in *nr (even on
error). If no data is read, this is considered to be an end of file
condition, and the caller of bfread() is
guaranteed to receive exactly one end-of-file condition.
bsize bytes from buffer buf.
Store the number of bytes written in *nw (even on error).
offset and whence
have the same meaning as for lseek()). Store the new
position at *pos which is an offset from the start of the
file.
BFILE object
is destroyed with bfile_dtor().
Returns 0 if successful, or an errno value otherwise.
bfile(), bfile_dtor() bfopen(). bfopenhandle(). bfread(). bfwrite(). bfseek(). bferror().
This function is part of the BFILE library.