STDIO (Re: TRUE and FALSE)

Chris Torek chris at mimsy.umd.edu
Sat Sep 8 07:43:28 AEST 1990


In article <STEPHEN.90Sep7125034 at estragon.uchicago.edu>
stephen at estragon.uchicago.edu (Stephen P Spackman) writes:
>Another thing that is needed is a function
>   FILE *pseudof
>     ( int (*producer)(void *handle, char *buf, size_t len)
>     , int (*consumer)(void *handle, char const *buf, size_t len)
>     , void *handle
>     , char const *mode
>     );
>
>that takes USER-DEFINED buffer readers and writers and makes a "FILE"
>object.

Gee, you mean like this one? :-)

	FILE *funopen(const void *_cookie,
		int (*readfn)(void *_cookie, char *_buf, int _n),
		int (*writefn)(void *_cookie, const char *_buf, int _n),
		fpos_t (*seekfn)(void *_cookie, fpos_t _off, int _whence),
		int (*closefn)(void *_cookie));

>That signature needs further thought - maybe it needs a flush/close
>function as well, e.g.; but it's not so far away.

No flush function is required, but seek and close functions are.

No `mode' is required either; this is implicit in the arguments.
(At least one of readfn and writefn must be non nil; if both are, the
function is a read-and-write.  All operations are `binary'; any `text'
conversion must be done in the read/write operations.)

This is running in the stdio on my 4.3BSD-reno-ish machine.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list