BFILE library: bfopen() - buffered file setup for files by filename

Name

bfopen() - buffered file setup for files by filename

Synopsis

#include "bfile.h"
#include "bfopen.h"

int bfopen(BFILE *bfp,
	char *filename,
	char *mode);

Decription

The bfopen() function makes a BFILE object refer to an open file by calling bfsetup() with appropriate parameters. filename is the name of the file. Characters in mode are interpreted independently as follows:

r
Open for reading. It is an error to use bfwrite() on a BFILE which has been opened with this flag.
w
Open for writing. It is an error to use bfread() on a BFILE which has been opened with this flag.
u
Open for update (read and write).
a
Make all writes (if any) append data to end of file.
b
Open in binary mode (in contrast to text mode).
c
File will be created if it does not exist.
t
File will be truncated to zero length if it exists.

Exactly one of 'r', 'w', and 'u' must be included. 'a', 'c' and 't' are not permitted if 'r' is used.

The BFILE object must not have previously been successfully associated with a file or other representation (i.e. none of bfopen(), bfopenhandle(), and bfsetup() can have been used unless they indicated failure). If bfopen() fails, it leaves the BFILE object unchanged (so this error isn't 'sticky' and will not be reported by the next call to bferror()).

Return value

Returns 0 if successful, or an errno value otherwise.

See also

bfile(), bfile_dtor(), bfsetup(), bfread(), bfwrite(), bferror().


This function is part of the BFILE library.