magic cookies given back by ftell, and used in fseek

Chris Torek chris at mimsy.UUCP
Sat May 28 05:22:58 AEST 1988


In article <1029 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe)
writes:
>What we have here is an abstract data type "stream position"
>whose representation happens to be an integer. ...

... which is somewhat unfortunate; the `format of choice' in C for
ADTs is an opaque pointer (`void *').

>I think it was Chris Torek who said that he had a new version of stdio
>which let the programmer specify his own read/write/close/&c.

Yes.  `&c' is `seek'; these are the only operations used in stdio itself.

>One thing I would like in that is programmer-defined stream position objects.

Unfortuantely, if the new interface is to be compatible with the old
---and this appears to be necessary to get the functions adopted anywhere;
certainly I would not install them here if they changed the return value
of fseek!---the return type must remain an integer (`long').

>I can't do [something useful] with only 32 bits to play with.  (Well,
>I can malloc() little blocks and return pointers to them, but there
>are problems with that.)

There *is* a solution, although it is not the prettiest:  Allocate a
block (`array') of real information, and return indicies into this
block (a la file descriptors).  The block can be expanded as necessary
by using realloc().  The Unix kernel simplifies the task by fixing
the number of descriptors (usually at something like 20 or 64 or 256).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list