Relative Byte Offsets

You get byte offsets by default when you are seeking or positioning in fixed-format binary files. You can also use byte offsets on a variable or undefined format file opened in binary mode with the byteseek parameter specified on the fopen() or freopen() function call. You can specify byteseek to be the default for fopen() calls by setting the environment variable _EDC_BYTE_SEEK to Y. See Using Environment Variables for information on how to set environment variables.

You do not need to acquire an offset from ftell() to seek to a relative position; you may specify a relative offset to fseek() with an origin of SEEK_SET. However, you cannot specify a negative offset to fseek() when you have specified SEEK_SET, because a negative offset would indicate a position before the beginning of the file. Also, you cannot specify a negative offset with origins of SEEK_CUR or SEEK_END such that the resulting file position would be before the beginning of the file. If you specify such an offset, fseek() fails.

If your file is not opened read-only, you can 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.

fseek() support of byte offsets in variable-format files generally requires reading all records from the origin to the new position. The impact on performance is greatest if you open an existing file for append in byteseek mode and then call ftell(). In this case, ftell() has to read from the beginning of the file to the current position to calculate the required byte offset. Support for byteseeking is intended to ease portability from other platforms. If you need better performance, consider using ftell()-encoded offsets, discussed in the next section.