diff options
| author | Charles-François Natali <neologix@free.fr> | 2012-01-10 20:25:09 +0100 |
|---|---|---|
| committer | Charles-François Natali <neologix@free.fr> | 2012-01-10 20:25:09 +0100 |
| commit | 76961faaa0323580caac8068848c33b7aeec13ee (patch) | |
| tree | 3ee6487ceb4e3c4674aabd0f92d7e06a1a09c09e /Modules/posixmodule.c | |
| parent | bda7a80194849eb2797c8bbffdbbaccad36d4583 (diff) | |
| download | cpython-git-76961faaa0323580caac8068848c33b7aeec13ee.tar.gz | |
Issue #13757: Change os.fdlistdir() so that it duplicates the passed file
descriptor (instead of closing it).
Diffstat (limited to 'Modules/posixmodule.c')
| -rw-r--r-- | Modules/posixmodule.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3c723cf288..a71d2e6426 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -2869,8 +2869,7 @@ posix_listdir(PyObject *self, PyObject *args) #ifdef HAVE_FDOPENDIR PyDoc_STRVAR(posix_fdlistdir__doc__, "fdlistdir(fd) -> list_of_strings\n\n\ -Like listdir(), but uses a file descriptor instead.\n\ -After succesful execution of this function, fd will be closed."); +Like listdir(), but uses a file descriptor instead."); static PyObject * posix_fdlistdir(PyObject *self, PyObject *args) @@ -2883,6 +2882,10 @@ posix_fdlistdir(PyObject *self, PyObject *args) errno = 0; if (!PyArg_ParseTuple(args, "i:fdlistdir", &fd)) return NULL; + /* closedir() closes the FD, so we duplicate it */ + fd = dup(fd); + if (fd < 0) + return posix_error(); Py_BEGIN_ALLOW_THREADS dirp = fdopendir(fd); Py_END_ALLOW_THREADS |
