[prev] 54 [next]

File Systems Operations

off_t lseek(int FileDesc, off_t Offset, int Whence)

  • set the "current position" of the FileDesc
  • Offset is in units of bytes, and can be negative
  • Whence can be one of ...
    • SEEK_SET ... set file position to Offset from start of file
    • SEEK_CUR ... set file position to Offset from current position
    • SEEK_END ... set file position to Offset from end of file
  • seeking beyond end of file leaves a gap which reads as 0's
  • seeking back beyond start of file sets position to start of file

Example:  lseek(fd, 0, SEEK_END);    (move to end of file)