The BFILE library provides buffered access to open files or other objects which have similar semantics to files. It provides functionality similar to the fread() and fwrite() functions in the standard stdio library. Its main differences are:
errno
. The use of global variables
is inappropriate for communication with libraries since it is
inefficient (especially for multi-threaded programs).
BFILE
object returns
zero to indicate success, or an errno value if an error occurs. Errors
are also 'sticky', so a BFILE
object which has experienced
an error will keep returning the error code for all operations attempted
until bferror() is called. This
avoids the need to continually check for errors when performing a
sequence of small reads, writes, and seeks.
The library can be regarded as implementing a class for general buffered access and two subclasses implementing buffered access for files specified by filename and for Windows HANDLEs.
Core functions in bfile.c
:
Supplementary functions:
bfhandle.c
bfopen.c
The BFILE library is distributed with Prosody which uses it in some of its high level libraries.