lseek(2) System Calls Manual lseek(2) lseek - , / C (libc, -lc) #include off_t lseek(int fd, off_t offset, int whence); lseek() , fd, offset whence, : SEEK_SET offset ( ). SEEK_CUR offset ( ). SEEK_END offset ( ). lseek() allows the file offset to be set beyond the end of the file (but this does not change the size of the file). If data is later written at this point, subsequent reads of the data in the gap (a "hole") return null bytes ('\0') until data is actually written into the gap. Since Linux 3.1, Linux supports the following additional values for whence: SEEK_DATA , offset, . offset , offset. SEEK_HOLE , offset. offset , offset. offset , (.., , ). , , , lseek() , offset . . , , , . , () . , -- ( , , , ). , : SEEK_HOLE , SEEK_DATA offset (.., , offset, , , ). SEEK_DATA SEEK_HOLE , _GNU_SOURCE. SEEK_HOLE SEEK_DATA : o Btrfs ( Linux 3.1) o OCFS ( Linux 3.2) o XFS ( Linux 3.5) o ext4 ( Linux 3.8) o tmpfs(5) ( Linux 3.8) o NFS ( Linux 3.18) o FUSE ( Linux 4.5) o GFS2 ( Linux 4.15) lseek() . (off_t) -1 errno . EBADF fd . EINVAL whence. , . ENXIO whence is SEEK_DATA or SEEK_HOLE, and offset is beyond the end of the file, or whence is SEEK_DATA and offset is within a hole at the end of the file. EOVERFLOW off_t. ESPIPE fd , FIFO. Linux lseek() ESPIPE. POSIX.1-2008. POSIX.1-2001, SVr4, 4.3BSD. SEEK_DATA SEEK_HOLE , Solaris, FreeBSD DragonFly BSD; POSIX ( 8). , open(2). O_APPEND , write(2) , lseek(). POSIX lseek(). dup(2), fallocate(2), fork(2), open(2), fseek(3), lseek64(3), posix_fallocate(3) () Artyom Kunyov , Azamat Hackimov , Dmitry Bolkhovskikh , Katrin Kutepova , Konstantin Shvaykovskiy , Yuri Kozlov , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux 6.9.1 15 2024 . lseek(2)