-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
bpo-39099: add scandir.dirfd() #17664
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
Changes from all commits
1f697bb
33e289e
e42da32
8e67098
ee4fbda
90aad94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| os.scandir() object has a new dirfd() method. (patch contributed by | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Markup could be used here. |
||
| Giampaolo Rodola) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13180,6 +13180,23 @@ ScandirIterator_close(ScandirIterator *self, PyObject *args) | |
| Py_RETURN_NONE; | ||
| } | ||
|
|
||
| #ifdef HAVE_DIRFD | ||
| static PyObject * | ||
| ScandirIterator_dirfd(ScandirIterator *self, PyObject *args) | ||
| { | ||
| int fd; | ||
|
|
||
| if (ScandirIterator_is_closed(self)) { | ||
| PyErr_SetString(PyExc_ValueError, "I/O operation on closed directory"); | ||
| return NULL; | ||
| } | ||
| fd = dirfd(self->dirp); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (fd == -1) | ||
| return path_error(&self->path); | ||
| return Py_BuildValue("i", fd); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| #endif /* HAVE_DIRFD */ | ||
|
|
||
| static PyObject * | ||
| ScandirIterator_enter(PyObject *self, PyObject *args) | ||
| { | ||
|
|
@@ -13235,6 +13252,9 @@ ScandirIterator_dealloc(ScandirIterator *iterator) | |
| static PyMethodDef ScandirIterator_methods[] = { | ||
| {"__enter__", (PyCFunction)ScandirIterator_enter, METH_NOARGS}, | ||
| {"__exit__", (PyCFunction)ScandirIterator_exit, METH_VARARGS}, | ||
| #ifdef HAVE_DIRFD | ||
| {"dirfd", (PyCFunction)ScandirIterator_dirfd, METH_NOARGS}, | ||
| #endif | ||
| {"close", (PyCFunction)ScandirIterator_close, METH_NOARGS}, | ||
| {NULL} | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
~will cause onlydirfdto be displayed.