fseek in VAX C

Bradford R. Daniels daniels at tle.enet.dec.com
Thu Jul 12 00:28:32 AEST 1990


What format is the file?  If it's a variable record length file, but the
records
are all the same size, you should be able to get to the previous by doing:

	fseek(fp, ftell(fp)-sizeof(record_type)-2,SEEK_SET)

(The -2 accounts for the 2-byte record size field.)  This work-around is,
of course, not supported, but it will get you there.

If the record format is fixed length, and the file's record size is the same
as sizeof(record_type), you can do:

	fseek(fp, ftell(fp)-sizeof(record_type),SEEK_SET)

Or even just make up an offset as long as it's a multiple of the file's
maximum record size.  Note that there's a good chance a future release
of VAX C will provide a way to position to arbitrary byte offsets in fixed
record length files.  Arbitrary positioning in variable record length file
is a much nastier problem, and one which may never satisfactorily be
resolved.

Of course, if it is a fixed format file, you can avoid the whole issue by
adding "ctx=stm" to your open() statement.  Your I/O will be slower,
but the Unix emulation is much better (including allowing arbitrary
byte positioning).

- Brad

-----------------------------------------------------------------
Brad Daniels			|  Digital Equipment Corp. almost
DEC Software Devo		|  definitely wouldn't approve of
"VAX C RTL Whipping Boy"	|  anything I say here...



More information about the Comp.lang.c mailing list