BFILE library: bfsetup() - buffered file setup

Name

bfsetup() - buffered file setup

Synopsis

#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);

Decription

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:

read
Read up to 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.
write
Write up to bsize bytes from buffer buf. Store the number of bytes written in *nw (even on error).
seek
Seek to given position (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.
close
Close the file. This is used when the BFILE object is destroyed with bfile_dtor().

Return value

Returns 0 if successful, or an errno value otherwise.

See also

bfile(), bfile_dtor() bfopen(). bfopenhandle(). bfread(). bfwrite(). bfseek(). bferror().


This function is part of the BFILE library.