Search code examples
cfseekfgetpos

Is fgetpos/fsetpos any faster than fseek?


I know fgetpos/fsetpos are used for returning to a file position.

But if I accessed that position with fseek to begin with, is it more efficient to use fgetpos/fsetpos to return later, or just the same fseek again?


Solution

  • Is fgetpos/fsetpos any faster than fseek?

    For general file positioning, fseek()/ftell() are limited to files sizes about LONG_MAX. fsetpos()/fgetpos() are designed to handle the file system's file sizes.

    For large files, fseek()/ftell() are not an option. @Thomas Padron-McCarthy

    When coding C99 onward, robust code uses fsetpos()/fgetpos() in lieu of a minor optimization that may of may not be present using the more limited fseek()/ftell().