Movatterモバイル変換


[0]ホーム

URL:


<<<PreviousHomeNext >>>


NAME

lseek - move the read/write file offset

SYNOPSIS

#include <unistd.h>

off_t lseek(int
fildes, off_toffset, intwhence);

DESCRIPTION

Thelseek() function shall set the file offset for the open file description associated with the file descriptorfildes, as follows:

The symbolic constants SEEK_SET, SEEK_CUR, and SEEK_END are defined in<unistd.h>.

The behavior oflseek() on devices which are incapable of seeking is implementation-defined. The value of the file offsetassociated with such a device is undefined.

Thelseek() function shall allow the file offset to be set beyond the end of the existing data in the file. If data islater written at this point, subsequent reads of data in the gap shall return bytes with the value 0 until data is actually writteninto the gap.

Thelseek() function shall not, by itself, extend the size of a file.

[SHM][Option Start]Iffildes refers to a shared memory object, the result of thelseek() function is unspecified.[Option End]

[TYM][Option Start]Iffildes refers to a typed memory object, the result of thelseek() function is unspecified.[Option End]

RETURN VALUE

Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, shall be returned.Otherwise, -1 shall be returned,errno shall be set to indicate the error, and the file offset shall remain unchanged.

ERRORS

Thelseek() function shall fail if:

[EBADF]
Thefildes argument is not an open file descriptor.
[EINVAL]
Thewhence argument is not a proper value, or the resulting file offset would be negative for a regular file, blockspecial file, or directory.
[EOVERFLOW]
The resulting file offset would be a value which cannot be represented correctly in an object of typeoff_t.
[ESPIPE]
Thefildes argument is associated with a pipe, FIFO, or socket.

The following sections are informative.

EXAMPLES

None.

APPLICATION USAGE

None.

RATIONALE

The ISO C standard includes the functionsfgetpos() andfsetpos(), which work on very large files by use of a special positioning type.

Althoughlseek() may position the file offset beyond the end of the file, this function does not itself extend the sizeof the file. While the only function in POSIX.1-2017 that may directly extend the size of the file iswrite(),truncate(), andftruncate(), several functions originally derived from the ISO C standard, such asfwrite(),fprintf(), and so on, may do so(by causing calls onwrite()).

An invalid file offset that would cause [EINVAL] to be returned may be both implementation-defined and device-dependent (forexample, 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 prohibitlseek() from returning a negative offset. Therefore, anapplication was required to clearerrno prior to the call and checkerrno upon return to determine whether a returnvalue of (off_t)-1 is a negative offset or an indication of an error condition. The standard developers did not wish torequire this action on the part of a conforming application, and chose to require thaterrno be set to [EINVAL] when theresulting file offset would be negative for a regular file, block special file, or directory.

FUTURE DIRECTIONS

None.

SEE ALSO

open

XBD<sys/types.h>,<unistd.h>

CHANGE HISTORY

First released in Issue 1. Derived from Issue 1 of the SVID.

Issue 5

The DESCRIPTION is updated for alignment with the POSIX Realtime Extension.

Large File Summit extensions are added.

Issue 6

In the SYNOPSIS, the optional include of the<sys/types.h> header isremoved.

The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:

An additional [ESPIPE] error condition is added for sockets.

The DESCRIPTION is updated for alignment with IEEE Std 1003.1j-2000 by specifying thatlseek() results areunspecified for typed memory objects.

Issue 7

POSIX.1-2008, Technical Corrigendum 1, XSH/TC1-2008/0366 [421] is applied.

End of informative text.

 

return to top of page


<<<PreviousHomeNext >>>


[8]ページ先頭

©2009-2025 Movatter.jp