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 - set file position indicator for stream to current value

&pagelevel(4)&pagelevel



Syntax

#include <stdio.h>

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

Description

pos, obtained from an earlier call to fgetpos().

fsetpos() clears the end-of-file indicator for the stream and undoes any effects of
ungetc() on the same stream. After an fsetpos() call, the next operation on an update
stream may be either input or output.

There is no difference in the functionality between fsetpos() and fsetpos64() except
that fsetpos64() uses an fpos64_t type.

Return val.

0

!= 0

if successful.

if an error occurs.

BS2000
errno is set to EBADF. (End)

Notes

The program environment determines whether fsetpos() is executed for a BS2000 or
POSIX file.

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

A successful call to the fsetpos() function deletes the EOF flag of the file and cancels all
the effects of the preceding ungetc calls for that file.

If new records are written to a text file that was opened in the write or append mode and an
fsetpos call is issued, any data that may still be in the buffer is first written 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, fseetpos()
does not insert a change of line (or record). In other words, the data is not automatically
terminated with a newline character when it is written from the buffer. Subsequent data
extends the record in the file. Consequently, when an ISAM file is read, only the newline
characters that were explicitly written by the program are read in.

After positioning, the next operation may be either a read or write operation.

For ISAM files, the function pair fgetpos()/fsetpos() is far more efficient than the
comparable function pair ftell()/fseek().

In the case of record I/O in ISAM files with key duplication, fsetpos() 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 deletion. fsetpos() can only be used to position on the first
record or after the last record of such a group. (End)

See also

fgetpos(), fseek(), ftell(), open(), rewind(), ungetc(), stdio.h.