Seek within a file (change the current offset where data is read and written).
Syntax
#include <unistd.h>
off_t lseek (int fd, off_t offset, int whence);
Parameters
-
fd
The file descriptor to use.
-
offset
The offset to apply, in bytes. See below for how it relates to
whence
. -
whence
The type of seeking to perform:
-
SEEK_CUR
: Add the offset to the current position. -
SEEK_SET
: Set the current position to the value of offset. -
SEEK_END
: Set the current position to the end of the file.
-
Return Value
If successful, the value returned is the new offset within the file in bytes from the beginning. Otherwise, the return value is negative and errno is set:
-
EBADF
Bad file descriptor.
-
ENOSYS
The system call is not supported for this file system, or not implemented.
Remarks
SocketFS, PipeFS and DevFS does not support lseek
.
The FATFS file system plugin does not support SEEK_CUR
.
ProcFS and KFS supports lseek
since 2019.10.13.