10000 gh-86768: check if fd is seekable in os.lseek on Windows by aisk · Pull Request #133137 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-86768: check if fd is seekable in os.lseek on Windows #133137

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Check error
  • Loading branch information
aisk committed Apr 29, 2025
commit 9a0d10f311c9edf7ee49146df46a82d6f048288a
10 changes: 9 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
# if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
# define HAVE_SYMLINK
# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */
extern int winerror_to_errno(int);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer used.

#endif


Expand Down Expand Up @@ -11438,6 +11439,7 @@ os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
if (result >= 0) {
if (GetFileType(h) != FILE_TYPE_DISK) {
// Only file is seekable
errno = ESPIPE;
result = -1;
}
}
Expand All @@ -11455,8 +11457,14 @@ os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how)
#endif
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
if (result < 0)
if (result < 0) {
#ifdef MS_WINDOWS
if (errno == 0) {
errno = winerror_to_errno(GetLastError());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use PyErr_SetFromWindowsErr(0)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SetFilePointerEx will set the error to GetLastError instead of errno, so we should check it. But after changed to call _lseeki64 directly, there is no need for this line of code.

#endif
posix_error();
}

return result;
}
Expand Down
Loading
0