File system

File system lseek

off_t lseek(int fd, off_t offset, int whence)

Seek to a position in a file. Affects where the next read or write will occur. Seeking past the end of the file does not immediately increase the size of the file, but will do so after the next write.

  • fd: The file descriptor for the file, return from the open call.
  • offset: Offset. The usage depends on whence. For SEEK_SET the offset must be >= 0. For SEEK_CUR it can be positive or negative to seek relative to the current position. Negative values used with SEEK_END move relative to the end-of-file.
  • whence:
    • SEEK_SET: Seek to offset bytes from the beginning of the file.
    • SEEK_CUR: Seek relative to the current file position.
    • SEEK_END: Seek relative to the end of the file. offset of 0 means seek to the end of the file when using SEEK_END.