Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fgetpos(DOS) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought

     Name
          fgetpos - Gets and stores the current value of a stream's
          file position indicator.

     Syntax
          #include <stdio.h>

          int fgetpos(stream, pos)
          FILE *stream;
          fpos_t *pos;


     Description
          The fgetpos function gets the current value of stream's file
          position indicator and stores it in the object that pos
          points to.  The fsetpos function can later use information
          stored in pos to reset stream's pointer to its position at
          the time fgetpos was called.

     Notes
          The pos value is stored in an internal format and is
          intended for use only by the fgetpos and fsetpos functions.

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

          EINVAL     The stream value is invalid.

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

     See Also
          fsetpos(DOS)

     Example
          #include <stdio.h>

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

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

                          fread(list,sizeof(char),100,stream);  /*
          Read some more */
                          if (fsetpos(stream,pos) != 0)  /* Return to
          saved position */
                                  perror("fsetpos error");
                 } }

          This program opens a file named file1 and reads 100
          characters. It then calls 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.

                                                (printed 6/18/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026