DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

fsetpos(S-osr5)


fsetpos -- sets the file position indicator for a stream

Syntax

cc . . . -lc

#include  <stdio.h>

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

Description

The fsetpos function sets the file position indicator for stream to the value of pos, which is obtained in a prior call to fgetpos against stream.

The function clears the end-of-file indicator and undoes any effects of the ungetc(stream). After calling fsetpos, the next operation on stream may be either input or output.

Return value

If successful, the fsetpos function returns 0. On failure, the function returns a nonzero value and sets errno to one of the following manifest constants (defined in stdio.h):


EBADF
The specified stream is not a valid file handle, or is not accessible.

EINVAL
The stream value is invalid.

See also

fgetpos(S-osr5)

Standards conformance

fsetpos is conformant with:

ANSI X3.159-1989 Programming Language -- C .

Example

   #include <stdio.h>
   

FILE *stream; fpos_t pos[]; int val; char list[100];

main() { /* open file1 */ if ((stream = fopen ("file1","rb")) == NULL) printf ("Trouble opening file\n"); else { /* Read some data */ fread (list, sizeof(char), 100, stream); /* Save current position */ if (fgetpos (stream, &pos) != 0) perror("fgetpos error"); /* Read some more */ fread (list, sizeof(char), 100, stream); /* Return to saved position */ if (fsetpos (stream, &pos) != 0) perror ("fsetpos error"); } }

This program opens the file named file1 and reads 100 characters. It then uses fgetpos to find and save the file position pointer. After performing another read, the program calls fsetpos to restore the file pointer to the saved position.


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005