What does Lseek return in C?

What does Lseek return in C?

lseek() is supposed to return the position of the file descriptor. The documentation says: Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file. Otherwise, a value of -1 is returned and errno is set to indicate the error.

What is the purpose of Lseek?

lseek() lets you specify new file offsets past the current end of the file. If data is written at such a point, read operations in the gap between this data and the old end of the file will return bytes containing binary zeros (or bytes containing blanks in the QSYS.

Which function returns a file descriptor?

open function
The open function creates and returns a new file descriptor for the file named by filename . Initially, the file position indicator for the file is at the beginning of the file. The argument mode (see Permission Bits) is used only when a file is created, but it doesn’t hurt to supply the argument in any case.

What is the purpose of a file descriptor?

In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket.

What is Lseek return policy?

RETURN VALUE Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file. Otherwise, a value of (off_t)-1 is returned and errno is set to indicate the error.

What does the lseek ( ) function do in Linux?

The lseek () function repositions the offset of the open file associated with the file descriptor fildes to the argument offset according to the directive whence as follows: The lseek () function allows the file offset to be set beyond the end of the file (but this does not change the size of the file).

What happens when data is written into a hole in lseek?

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. Upon successful completion, lseek () returns the resulting offset location as measured in bytes from the beginning of the file.

What does lseek mean in C system call?

lseek (C System Call): lseek is a system call that is used to change the location of the read/write pointer of a file descriptor. The location can be set either in absolute or relative terms. off_t offset : The offset of the pointer (measured in bytes). (rela, absolute, etc.).

How to change the location of a file descriptor?

lseek (C System Call): lseek is a system call that is used to change the location of the read/write pointer of a file descriptor. The location can be set either in absolute or relative terms. Function Definition. off_t lseek (int fildes, off_t offset, int whence); Field Description.