Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
70273da3
Commit
70273da3
authored
Jan 10, 2012
by
Charles-François Natali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #13757: Change os.fdlistdir() so that it duplicates the passed file
descriptor (instead of closing it).
parent
c4f9ce8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
11 deletions
+8
-11
Doc/library/os.rst
Doc/library/os.rst
+1
-1
Lib/test/test_posix.py
Lib/test/test_posix.py
+2
-8
Modules/posixmodule.c
Modules/posixmodule.c
+5
-2
No files found.
Doc/library/os.rst
View file @
70273da3
...
...
@@ -772,7 +772,7 @@ as internal buffering of data.
.. function:: fdlistdir(fd)
Like :func:`listdir`, but uses a file descriptor instead and always returns
strings.
After execution of this function, *fd* will be closed.
strings.
Availability: Unix.
...
...
Lib/test/test_posix.py
View file @
70273da3
...
...
@@ -455,20 +455,14 @@ class PosixTester(unittest.TestCase):
def
test_fdlistdir
(
self
):
f
=
posix
.
open
(
posix
.
getcwd
(),
posix
.
O_RDONLY
)
self
.
addCleanup
(
posix
.
close
,
f
)
f1
=
posix
.
dup
(
f
)
self
.
assertEqual
(
sorted
(
posix
.
listdir
(
'.'
)),
sorted
(
posix
.
fdlistdir
(
f
1
))
sorted
(
posix
.
fdlistdir
(
f
))
)
# Check the fd was closed by fdlistdir
with
self
.
assertRaises
(
OSError
)
as
ctx
:
posix
.
close
(
f1
)
self
.
assertEqual
(
ctx
.
exception
.
errno
,
errno
.
EBADF
)
# Check that the fd offset was reset (issue #13739)
f2
=
posix
.
dup
(
f
)
self
.
assertEqual
(
sorted
(
posix
.
listdir
(
'.'
)),
sorted
(
posix
.
fdlistdir
(
f
2
))
sorted
(
posix
.
fdlistdir
(
f
))
)
def
test_access
(
self
):
...
...
Modules/posixmodule.c
View file @
70273da3
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment