magic cookies given back by ftell, and used in fseek
Richard A. O'Keefe
ok at quintus.UUCP
Thu May 26 17:49:12 AEST 1988
In article <129 at lakart.UUCP>, dg at lakart.UUCP (David Goodenough) writes:
> There has been much discussion in this group on the fact that on certain
> systems (VMS I believe), ftell & fseek use magic cookies to tell about
> file position. I have my asbestos suit ready if this suggestion is out of
> line, but have the ANSI comittee considered providing some means to convert
> from cookie format to and from character position in file. Come to that
> is such a thing possible?
Given the history of C, I suggest that the "magic cookie" idea may have had
more to do with the /370 or GECOS(sp?) implementations of C than with VMS.
Consider an IBM/370 "VB" file (variable length blocked records). The
operating system wants you to position in the file by specifying the
relative block number (this is gross oversimplification, please don't
flame me, IBM fans). If "character position" is interpreted as
(count of previous *blocks*) x (size of block) + (offset in current block)
then something could be done, but that won't be equal to the number of
characters getc() gave you while you were getting there. For *real* fun
(fun until it hurts) try to figure out what magic cookies should do with
concatenated data sets.
Magic cookies should really be some sort of implementation-specific record.
The UNIX "ftell" manual page warns that on non-UNIX systems "arithmetic may
not meaningfully be performed on" magic cookies, and you have to regard
comparing for equality as arithmetic. All you can do with a magic cookie
is say "go back there".
More information about the Comp.lang.c
mailing list