gtpc2m2h | C/C++ Language Support User's Guide |
This function gets a file position.
Format
#include <stdio.h> int fgetpos(FILE *stream, fpos_t *pos);
This function stores the current value of the file pointer associated with stream into the object pointed to by pos. The value pointed to by pos can be used later in a call to the fsetpos function to reposition the stream pointed to by stream.
Both the fgetpos and fsetpos functions also save state information for wide-oriented files. The value stored in pos is not specified and is used only by the fsetpos function.
The position returned by the fgetpos function is affected by the ungetc functions. Each call to these functions causes the file position indicator to be backed up from the position where the ungetc function was issued. For details about how ungetc affects fgetpos function behavior, see ungetc-Push Character to Input Stream.
Normal Return
If successful, the fgetpos function returns 0.
Error Return
If unsuccessful, the fgetpos function returns a nonzero value.
Programming Considerations
None.
Examples
The following example opens the myfile.dat file for reading. The current file pointer position is stored into the pos variable.
#include <stdio.h> int main(void) { FILE *stream; int retcode; fpos_t pos; stream = fopen("myfile.dat", "rb"); /* The value returned by fgetpos can be used by fsetpos() to set the file pointer if 'retcode' is 0 */ if ((retcode = fgetpos(stream, &pos)) == 0) printf("Current position of file pointer found\n"); fclose(stream); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.