off_t lseek(int fildes, off_t offset, int
The lseek() function shall set the file offset for the open file description associated with the file descriptor fildes, as follows:
The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are defined in <unistd.h>.
The behavior of lseek() on devices which are incapable of seeking is implementation-defined. The value of the file offset associated with such a device is undefined.
The lseek() function shall allow the file offset to be set beyond the end of the existing data in the file. If data is later written at this point, subsequent reads of data in the gap shall return bytes with the value 0 until data is actually written into the gap.
The lseek() function shall not, by itself, extend the size of a file.
If fildes refers to a shared memory object, the result of the lseek() function is unspecified.
If fildes refers to a typed memory object, the result of the lseek() function is unspecified.
Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned. Otherwise, (off_t)-1 shall be returned, errno shall be set to indicate the error, and the file offset shall remain unchanged.
The lseek() function shall fail if:
The following sections are informative.
The ISO C standard includes the functions fgetpos() and fsetpos(), which work on very large files by use of a special positioning type.
Although lseek() may position the file offset beyond the end of the file, this function does not itself extend the size of the file. While the only function in IEEE Std 1003.1-2001 that may directly extend the size of the file is write(), truncate(), and ftruncate(), several functions originally derived from the ISO C standard, such as fwrite(), fprintf(), and so on, may do so (by causing calls on write()).
An invalid file offset that would cause [EINVAL] to be returned may be both implementation-defined and device-dependent (for example, memory may have few invalid values). A negative file offset may be valid for some devices in some implementations.
The POSIX.1-1990 standard did not specifically prohibit lseek() from returning a negative offset. Therefore, an application was required to clear errno prior to the call and check errno upon return to determine whether a return value of ( off_t)-1 is a negative offset or an indication of an error condition. The standard developers did not wish to require this action on the part of a conforming application, and chose to require that errno be set to [EINVAL] when the resulting file offset would be negative for a regular file, block special file, or directory.
open() , the Base Definitions volume of IEEE Std 1003.1-2001, <sys/types.h>, <unistd.h>