Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fsetpos, fsetpos64 - Position read/write pointer

&pagelevel(4)&pagelevel

Definition    

#include <stdio.h>

int fsetpos(FILE *fp, const fpos_t *pos);
int fsetpos64(FILE *fp, const fpos64_t *pos);

fsetpos and fsetpos64 set the read/write pointer of the file with file pointer fp to a position pos previously determined by fgetpos or fgetpos64.
After positioning, the next operation can be a read or a write function.

To process files > 2 GB, proceed as follows:

  • If the _FILE_OFFSET_BITS 64 define (see "Support for DMS and UFS files > 2 GB") is set, call freopen. freopen64 is then used implicitly with the appropriate parameters.

  • Otherwise, you have to call freopen64.

There is no functional difference between fsetpos and fsetpos64, except that
fsetpos64 uses an fpos64_t type.

Return val.

0

On successful execution of fsetpos.


!= 0

In the event of an error. In addition, errno is set to EBADF.

Notes

fsetpos and fsetpos64 can be used on binary files (SAM in binary mode, PAM, INCORE) and text files (SAM in text mode, ISAM).
fsetpos and fsetpos64 cannot be used on system files (SYSDTA, SYSLST, SYSOUT).

A successful fsetpos or fsetpos64 call deletes the EOF flag of the file and cancels all the effects of preceding ungetc calls for this file.

If new records are written to a text file (opened for creation or in append mode) and a fsetpos or fsetpos64 call is issued any residual data is first written from the buffer to the file and terminated with a newline character (\n).
Exception for ANSI functionality:
If the data of an ISAM file in the buffer does not end in a newline character, fsetpos or fsetpos64 does not cause a change of line (or change of record), i.e. the data is not automatically terminated with a newline character when writing from the buffer. Subsequent data lengthens the record in the file. When an ISAM file is read, therefore, only those newline characters explicitly written by the program are read in.

For ISAM files the function pair fgetpos/fsetpos or fgetpos64/fsetpos64 is considerably more efficient than the comparable function pair ftell/fseek or ftell64/fseek64.

Record I/O

In ISAM files with key duplication, fsetpos and fsetpos64 cannot be used to position on the second or higher record of a group with identical keys. This can only be done by sequential reading or deleting.
With fsetpos and fsetpos64 it is only possible to position on the first record or after thelast record of such a group.

See also

fgetpos, fgetpos64, fseek, fseek64, ftell, ftell64