a couple of random questions
Stephen J. Friedl
friedl at vsi.UUCP
Wed Apr 13 13:57:05 AEST 1988
Hiho there,
Two random questions. First, the word "entry" used to be a
reserved keyword in C but appears to never have been used. Does
anybody know the direction it might have taken had its use been
implemented? I recall vaguely about a similar keyword in FORTRAN
but wonder if anybody has any stories from long ago in days of old.
Second, what is the portable way to rewind a Unix file
descriptor? On almost every machine I have ever used:
lseek(fd, (off_t)0, SEEK_SET);
works because the offset is a byte count, but it is inevitable
that on some machine, off_t is the pointer to some kind of
struct, or at least is *not* simply a byte count. What other
machines might work this way? I know that the good old BDS C
compiler for the Z-80 measured its offset in records, but
nevertheless a zero arg did the trick.
Related to this, how about a portable way to back up one
record? On the assumption that doing math on an off_t is not
portable, I basically save the offset just before a read:
#define tell(fd) lseek(fd, (off_t)0, SEEK_CUR)
extern off_t lseek( /* int fd, off_t offset, int whence */ );
{
off_t off;
while (off = tell(fd), read(fd, buf, SIZE) == SIZE)
if (some.condition->here)
lseek(fd, off, SEEK_SET); /* back up */
Note that this is largely an academic exercise, and I know that
using dpANS buffered I/O resolves these issues, but I'm just
curious...
--
Steve Friedl V-Systems, Inc. "Yes, I'm jeff at unh's brother"
friedl at vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl
More information about the Comp.lang.c
mailing list