Skip to content

[3.12] gh-107801: Improve the accuracy of os.lseek docs (#107935) #108136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1163,17 +1163,22 @@ as internal buffering of data.
.. versionadded:: 3.11


.. function:: lseek(fd, pos, how, /)
.. function:: lseek(fd, pos, whence, /)

Set the current position of file descriptor *fd* to position *pos*, modified
by *how*: :const:`SEEK_SET` or ``0`` to set the position relative to the
beginning of the file; :const:`SEEK_CUR` or ``1`` to set it relative to the
current position; :const:`SEEK_END` or ``2`` to set it relative to the end of
the file. Return the new cursor position in bytes, starting from the beginning.
by *whence*, and return the new position in bytes relative to
the start of the file.
Valid values for *whence* are:

* :const:`SEEK_SET` or ``0`` -- set *pos* relative to the beginning of the file
* :const:`SEEK_CUR` or ``1`` -- set *pos* relative to the current file position
* :const:`SEEK_END` or ``2`` -- set *pos* relative to the end of the file
* :const:`SEEK_HOLE` -- set *pos* to the next data location, relative to *pos*
* :const:`SEEK_DATA` -- set *pos* to the next data hole, relative to *pos*

.. versionchanged:: 3.3

Add support for :const:`SEEK_HOLE` and :const:`SEEK_DATA`.
Add support for :const:`!SEEK_HOLE` and :const:`!SEEK_DATA`.


.. data:: SEEK_SET
Expand Down
17 changes: 13 additions & 4 deletions Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -10421,19 +10421,24 @@ os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length)
os.lseek -> Py_off_t

fd: int
An open file descriptor, as returned by os.open().
position: Py_off_t
how: int
Position, interpreted relative to 'whence'.
whence as how: int
The relative position to seek from. Valid values are:
- SEEK_SET: seek from the start of the file.
- SEEK_CUR: seek from the current file position.
- SEEK_END: seek from the end of the file.
/

Set the position of a file descriptor. Return the new position.

Return the new cursor position in number of bytes
relative to the beginning of the file.
The return value is the number of bytes relative to the beginning of the file.
[clinic start generated code]*/

static Py_off_t
os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
/*[clinic end generated code: output=971e1efb6b30bd2f input=902654ad3f96a6d3]*/
/*[clinic end generated code: output=971e1efb6b30bd2f input=f096e754c5367504]*/
{
Py_off_t result;

Expand Down