All rights reserved.
This code is derived from software contributed to Berkeley by
Chris Torek.
%sccs.include.redist.man%
@(#)funopen.3 5.1 (Berkeley) 03/05/91
#include <stdio.h> FILE * funopen(void *cookie, int (*readfn)(void *, char *, int),old man macros need the reset of bold modeold man macros need the reset of bold mode
int (*writefn)(void *, char *, int), fpos_t (*seekfn)(void *, off_t, int), int (*closefn)(void *));
FILE * fropen(void *cookie, int (*readfn)(void *, char *, int)); FILE * fwopen(void *cookie, int (*writefn)(void *, char *, int));
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 readfn , writefn , seekfn and closefn must match those, respectively, of read (2), write (2), seek (2), and close (2) with the single exception that they are passed the cookie argument specified to funopen in place of the traditional file descriptor argument.
Read and write I/O functions are allowed to change the underlying buffer on fully buffered or line buffered streams by calling setvbuf . 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.
All user I/O functions can report an error by returning -1. Additionally, all of the functions should set the external variable errno appropriately if an error occurs.
An error on closefn does not keep the stream open.
As a convenience, the include file ``<stdio.h>'' defines the macros fropen and fwopen as calls to funopen with only a read or write function specified.
15 [EINVAL] Funopen was called without either a read or write function. Funopen may also fail and set errno for any of the errors specified for the routine malloc (3).