Get the current position of a stream
#include <stdio.h> int fgetpos( FILE* fp, fpos_t* pos );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The fgetpos() function stores the current position of the stream fp in the fpos_t object specified by pos.
You can use the value stored in pos in a call to fsetpos() if you want to reposition the file to the position at the time of the fgetpos() call.
0 for success, or nonzero if an error occurs (errno is set).
#include <stdio.h> #include <stdlib.h> int main( void ) { FILE *fp; fpos_t position; char buffer[80]; fp = fopen( "file", "r" ); if( fp != NULL ) { fgetpos( fp, &position ); /* get position */ fgets( buffer, 80, fp ); /* read record */ fsetpos( fp, &position ); /* set position */ fgets( buffer, 80, fp ); /* read same record */ fclose( fp ); return EXIT_SUCCESS; } return EXIT_FAILURE; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fopen(), fseek(), fsetpos(), ftell()