Encoded Offsets
If you do not specify the byteseek
parameter and you set the _EDC_BYTE_SEEK
variable to N
, any variable- or undefined-format binary
file gets encoded offsets from ftell(). This keeps this release of LE/VSE C Run-Time compatible
with code generated by old releases of C/370.
Encoded offsets are values representing the block number and the
relative byte within that block, all within one long int
.
Because LE/VSE C Run-Time does not document its encoding scheme, you cannot
rely on any encoded offset not returned by ftell(), except 0
,
which is the beginning of the file. This includes encoded offsets
that you adjust yourself (for example, with addition or subtraction).
When you call fseek() with the origin
SEEK_SET
,
you must use either 0
or an encoded offset returned from ftell().
For origin
s of SEEK_CUR
and SEEK_END
, however,
you specify relative byte offsets. If you want to seek to a certain
relative byte offset, you can use SEEK_SET
with an offset of 0
to
rewind the file to the beginning, and then you can use SEEK_CUR
to
specify the desired relative byte offset.
In earlier releases of C, ftell() could determine position only for files with no more than 131,071 blocks. In the new design, this number increases depending on the block size. From a maximum block size of 32,760, every time this number decreases by half, the number of blocks that can be represented doubles.
If your file is not opened read-only, you can use SEEK_CUR
or SEEK_END
to specify a position that is beyond the current EOF
.
In such cases, a new end-of-file position is created; null characters
are automatically added between the old EOF
and the new EOF
.
For SEEK_SET
, because you are restricted to using offsets returned
by ftell(), any offset that indicates a position outside the current
file is invalid and causes fseek() to fail.