Show More
@@ -7,6 +7,7 b'' | |||
|
7 | 7 | the GNU General Public License, incorporated herein by reference. |
|
8 | 8 | */ |
|
9 | 9 | |
|
10 | #define _ATFILE_SOURCE | |
|
10 | 11 | #include <Python.h> |
|
11 | 12 | #include <dirent.h> |
|
12 | 13 | #include <fcntl.h> |
@@ -15,10 +16,6 b'' | |||
|
15 | 16 | #include <sys/types.h> |
|
16 | 17 | #include <unistd.h> |
|
17 | 18 | |
|
18 | #if defined(__sun) | |
|
19 | #define dirfd(dir) ((dir)->dd_fd) | |
|
20 | #endif | |
|
21 | ||
|
22 | 19 | struct listdir_stat { |
|
23 | 20 | PyObject_HEAD |
|
24 | 21 | struct stat st; |
@@ -165,7 +162,7 b' static PyObject *listfiles(PyObject *lis' | |||
|
165 | 162 | } |
|
166 | 163 | |
|
167 | 164 | static PyObject *statfiles(PyObject *list, PyObject *ctor_args, int keep, |
|
168 |
char *path, int len, |
|
|
165 | char *path, int len, int dfd) | |
|
169 | 166 | { |
|
170 | 167 | struct stat buf; |
|
171 | 168 | struct stat *stp = &buf; |
@@ -196,7 +193,11 b' static PyObject *statfiles(PyObject *lis' | |||
|
196 | 193 | PyTuple_SET_ITEM(elt, 2, py_st); |
|
197 | 194 | } |
|
198 | 195 | |
|
196 | #ifdef AT_SYMLINK_NOFOLLOW | |
|
197 | ret = fstatat(dfd, name, stp, AT_SYMLINK_NOFOLLOW); | |
|
198 | #else | |
|
199 | 199 | ret = lstat(path, stp); |
|
200 | #endif | |
|
200 | 201 | if (ret == -1) |
|
201 | 202 | return PyErr_SetFromErrnoWithFilename(PyExc_OSError, |
|
202 | 203 | path); |
@@ -244,6 +245,7 b' static PyObject *listdir(PyObject *self,' | |||
|
244 | 245 | char full_path[PATH_MAX + 10]; |
|
245 | 246 | int path_len; |
|
246 | 247 | int need_stat, keep_stat; |
|
248 | int dfd; | |
|
247 | 249 | |
|
248 | 250 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:listdir", kwlist, |
|
249 | 251 | &path, &path_len, &statobj)) |
@@ -251,7 +253,13 b' static PyObject *listdir(PyObject *self,' | |||
|
251 | 253 | |
|
252 | 254 | keep_stat = statobj && PyObject_IsTrue(statobj); |
|
253 | 255 | |
|
256 | #ifdef AT_SYMLINK_NOFOLLOW | |
|
257 | dfd = open(path, O_RDONLY); | |
|
258 | dir = fdopendir(dfd); | |
|
259 | #else | |
|
254 | 260 | dir = opendir(path); |
|
261 | dfd = -1; | |
|
262 | #endif | |
|
255 | 263 | if (!dir) { |
|
256 | 264 | err = PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
|
257 | 265 | goto bail; |
@@ -274,7 +282,7 b' static PyObject *listdir(PyObject *self,' | |||
|
274 | 282 | if (!keep_stat && !need_stat) |
|
275 | 283 | goto done; |
|
276 | 284 | |
|
277 |
err = statfiles(list, ctor_args, keep_stat, full_path, path_len, d |
|
|
285 | err = statfiles(list, ctor_args, keep_stat, full_path, path_len, dfd); | |
|
278 | 286 | if (!err) |
|
279 | 287 | goto done; |
|
280 | 288 |
General Comments 0
You need to be logged in to leave comments.
Login now