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
8250e23a
Commit
8250e23a
authored
Feb 25, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10755: Add the posix.fdlistdir() function. Patch by Ross Lagerwall.
parent
f65132de
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
108 additions
and
5 deletions
+108
-5
Doc/library/os.rst
Doc/library/os.rst
+10
-0
Lib/test/test_posix.py
Lib/test/test_posix.py
+12
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/posixmodule.c
Modules/posixmodule.c
+73
-0
configure
configure
+3
-3
configure.in
configure.in
+2
-2
pyconfig.h.in
pyconfig.h.in
+6
-0
No files found.
Doc/library/os.rst
View file @
8250e23a
...
...
@@ -733,6 +733,16 @@ as internal buffering of data.
This function is not available on MacOS.
.. 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.
Availability: Unix.
.. versionadded:: 3.3
.. function:: fpathconf(fd, name)
Return system configuration information relevant to an open file. *name*
...
...
Lib/test/test_posix.py
View file @
8250e23a
...
...
@@ -285,6 +285,18 @@ class PosixTester(unittest.TestCase):
if
hasattr
(
posix
,
'listdir'
):
self
.
assertTrue
(
support
.
TESTFN
in
posix
.
listdir
())
@
unittest
.
skipUnless
(
hasattr
(
posix
,
'fdlistdir'
),
"test needs posix.fdlistdir()"
)
def
test_fdlistdir
(
self
):
f
=
posix
.
open
(
posix
.
getcwd
(),
posix
.
O_RDONLY
)
self
.
assertEqual
(
sorted
(
posix
.
listdir
(
'.'
)),
sorted
(
posix
.
fdlistdir
(
f
))
)
# Check the fd was closed by fdlistdir
with
self
.
assertRaises
(
OSError
)
as
ctx
:
posix
.
close
(
f
)
self
.
assertEqual
(
ctx
.
exception
.
errno
,
errno
.
EBADF
)
def
test_access
(
self
):
if
hasattr
(
posix
,
'access'
):
self
.
assertTrue
(
posix
.
access
(
support
.
TESTFN
,
os
.
R_OK
))
...
...
Misc/NEWS
View file @
8250e23a
...
...
@@ -35,6 +35,8 @@ Core and Builtins
Library
-------
- Issue #10755: Add the posix.fdlistdir() function. Patch by Ross Lagerwall.
- Issue #4761: Add the *at() family of functions (openat(), etc.) to the posix
module. Patch by Ross Lagerwall.
...
...
Modules/posixmodule.c
View file @
8250e23a
...
...
@@ -2678,6 +2678,76 @@ posix_listdir(PyObject *self, PyObject *args)
#endif
/* which OS */
}
/* end of posix_listdir */
#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."
);
static
PyObject
*
posix_fdlistdir
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
d
,
*
v
;
DIR
*
dirp
;
struct
dirent
*
ep
;
int
fd
;
errno
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"i:fdlistdir"
,
&
fd
))
return
NULL
;
Py_BEGIN_ALLOW_THREADS
dirp
=
fdopendir
(
fd
);
Py_END_ALLOW_THREADS
if
(
dirp
==
NULL
)
{
close
(
fd
);
return
posix_error
();
}
if
((
d
=
PyList_New
(
0
))
==
NULL
)
{
Py_BEGIN_ALLOW_THREADS
closedir
(
dirp
);
Py_END_ALLOW_THREADS
return
NULL
;
}
for
(;;)
{
errno
=
0
;
Py_BEGIN_ALLOW_THREADS
ep
=
readdir
(
dirp
);
Py_END_ALLOW_THREADS
if
(
ep
==
NULL
)
{
if
(
errno
==
0
)
{
break
;
}
else
{
Py_BEGIN_ALLOW_THREADS
closedir
(
dirp
);
Py_END_ALLOW_THREADS
Py_DECREF
(
d
);
return
posix_error
();
}
}
if
(
ep
->
d_name
[
0
]
==
'.'
&&
(
NAMLEN
(
ep
)
==
1
||
(
ep
->
d_name
[
1
]
==
'.'
&&
NAMLEN
(
ep
)
==
2
)))
continue
;
v
=
PyUnicode_DecodeFSDefaultAndSize
(
ep
->
d_name
,
NAMLEN
(
ep
));
if
(
v
==
NULL
)
{
Py_CLEAR
(
d
);
break
;
}
if
(
PyList_Append
(
d
,
v
)
!=
0
)
{
Py_DECREF
(
v
);
Py_CLEAR
(
d
);
break
;
}
Py_DECREF
(
v
);
}
Py_BEGIN_ALLOW_THREADS
closedir
(
dirp
);
Py_END_ALLOW_THREADS
return
d
;
}
#endif
#ifdef MS_WINDOWS
/* A helper function for abspath on win32 */
static
PyObject
*
...
...
@@ -8599,6 +8669,9 @@ static PyMethodDef posix_methods[] = {
{
"link"
,
posix_link
,
METH_VARARGS
,
posix_link__doc__
},
#endif
/* HAVE_LINK */
{
"listdir"
,
posix_listdir
,
METH_VARARGS
,
posix_listdir__doc__
},
#ifdef HAVE_FDOPENDIR
{
"fdlistdir"
,
posix_fdlistdir
,
METH_VARARGS
,
posix_fdlistdir__doc__
},
#endif
{
"lstat"
,
posix_lstat
,
METH_VARARGS
,
posix_lstat__doc__
},
{
"mkdir"
,
posix_mkdir
,
METH_VARARGS
,
posix_mkdir__doc__
},
#ifdef HAVE_NICE
...
...
configure
View file @
8250e23a
#! /bin/sh
# From configure.in Revision: 886
08
.
# From configure.in Revision: 886
24
.
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.65 for python 3.3.
#
...
...
@@ -9311,8 +9311,8 @@ $as_echo "MACHDEP_OBJS" >&6; }
# checks for library functions
for
ac_func
in
alarm accept4 setitimer getitimer bind_textdomain_codeset
chown
\
clock confstr ctermid execv faccessat fchmod fchmodat fchown fchownat
fork
\
fpathconf fstatat ftime ftruncate futimesat
\
clock confstr ctermid execv faccessat fchmod fchmodat fchown fchownat
\
f
dopendir fork f
pathconf fstatat ftime ftruncate futimesat
\
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid
\
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd
\
initgroups
kill
killpg lchmod lchown linkat lstat mbrtowc mkdirat
mkfifo
\
...
...
configure.in
View file @
8250e23a
...
...
@@ -2534,8 +2534,8 @@ AC_MSG_RESULT(MACHDEP_OBJS)
# checks for library functions
AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
clock confstr ctermid execv faccessat fchmod fchmodat fchown fchownat
fork
\
fpathconf fstatat ftime ftruncate futimesat \
clock confstr ctermid execv faccessat fchmod fchmodat fchown fchownat \
f
dopendir fork f
pathconf fstatat ftime ftruncate futimesat \
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
initgroups kill killpg lchmod lchown linkat lstat mbrtowc mkdirat mkfifo \
...
...
pyconfig.h.in
View file @
8250e23a
...
...
@@ -229,6 +229,9 @@
/* Define if you have the 'fdatasync' function. */
#undef HAVE_FDATASYNC
/* Define to 1 if you have the `fdopendir' function. */
#undef HAVE_FDOPENDIR
/* Define to 1 if you have the `finite' function. */
#undef HAVE_FINITE
...
...
@@ -533,6 +536,9 @@
/* Define if the OS supports pipe2() */
#undef HAVE_PIPE2
/* Define if the OS supports pipe2() */
#undef HAVE_PIPE2
/* Define to 1 if you have the `plock' function. */
#undef HAVE_PLOCK
...
...
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