Section: C Library Functions (3)Index
Return to Main Contents
- open a stream
Ft FILE *
Fn funopen const void *cookie int (*readfn)(void *, char *, int) int (*writefn)(void *, const char *, int) off_t (*seekfn)(void *, off_t, int) int (*closefn)(void *)
Ft FILE *
Fn fropen void *cookie int (*readfn)(void *, char *, int)
Ft FILE *
Fn fwopen void *cookie int (*writefn)(void *, const char *, int)
associates a stream with up to four
must be specified;
the others can be given as an appropriately-typed
functions will be used to read, write, seek and
close the new stream.
In general, omitting a function means that any attempt to perform the
associated operation on the resulting stream will fail.
If the close function is omitted, closing the stream will flush
any buffered output and then succeed.
The calling conventions of
Fa readfn ,
Fa writefn ,
must match those, respectively, of
with the single exception that they are passed the
argument specified to
in place of the traditional file descriptor argument.
Read and write
functions are allowed to change the underlying buffer
on fully buffered or line buffered streams by calling
They are also not required to completely fill or empty the buffer.
They are not, however, allowed to change streams from unbuffered to buffered
or to change the state of the line buffering flag.
They must also be prepared to have read or write calls occur on buffers other
than the one most recently specified.
functions can report an error by returning -1.
Additionally, all of the functions should set the external variable
appropriately if an error occurs.
An error on
does not keep the stream open.
As a convenience, the include file
defines the macros
as calls to
with only a read or write function specified.
Upon successful completion,
is returned and the global variable
is set to indicate the error.
- Bq Er EINVAL
was called without either a read or write function.
may also fail and set
for any of the errors
specified for the routine
functions first appeared in
may not be portable to systems other than
interface erroneously assumes that
is an integral type, and uses it in the
hook; but because code using a
hook will fail to build on systems where
is a struct, and it will need to be slightly fixed anyway, the
implementation provided by libbsd (in the same way as
uses the correct
- RETURN VALUES
- SEE ALSO