Show More
@@ -47,12 +47,12 static struct PyGetSetDef listdir_stat_g | |||
|
47 | 47 | |
|
48 | 48 | static PyObject *listdir_stat_new(PyTypeObject *t, PyObject *a, PyObject *k) |
|
49 | 49 | { |
|
50 |
|
|
|
50 | return t->tp_alloc(t, 0); | |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | static void listdir_stat_dealloc(PyObject *o) |
|
54 | 54 | { |
|
55 |
|
|
|
55 | o->ob_type->tp_free(o); | |
|
56 | 56 | } |
|
57 | 57 | |
|
58 | 58 | static PyTypeObject listdir_stat_type = { |
@@ -111,6 +111,8 static inline int mode_to_kind(int mode) | |||
|
111 | 111 | |
|
112 | 112 | static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) |
|
113 | 113 | { |
|
114 | static char *kwlist[] = { "path", "stat", NULL }; | |
|
115 | PyObject *statobj = NULL; | |
|
114 | 116 |
|
|
115 | 117 |
|
|
116 | 118 |
|
@@ -121,38 +123,38 static PyObject *listdir(PyObject *self, | |||
|
121 | 123 |
|
|
122 | 124 |
|
|
123 | 125 |
|
|
124 | ||
|
125 | { | |
|
126 | static char *kwlist[] = { "path", "stat", NULL }; | |
|
127 | PyObject *statobj = NULL; | |
|
126 | ssize_t size; | |
|
127 | ssize_t i; | |
|
128 | int dfd; | |
|
128 | 129 | |
|
129 | 130 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|O:listdir", kwlist, |
|
130 | 131 | &path, &path_len, &statobj)) |
|
131 | 132 |
|
|
132 | 133 | |
|
133 | 134 | do_stat = statobj && PyObject_IsTrue(statobj); |
|
134 | } | |
|
135 | 135 | |
|
136 |
|
|
|
136 | dir = opendir(path); | |
|
137 | if (!dir) { | |
|
137 | 138 | list = PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
|
138 | 139 |
|
|
139 | 140 | } |
|
140 | 141 | |
|
141 |
|
|
|
142 | list = PyList_New(0); | |
|
143 | if (!list) | |
|
142 | 144 |
|
|
143 | 145 | |
|
144 | 146 |
|
|
145 | 147 |
|
|
146 | 148 |
|
|
147 | 149 | |
|
148 | while ((ent = readdir(dir))) { | |
|
150 | for (ent = readdir(dir); ent; ent = readdir(dir)) { | |
|
149 | 151 |
|
|
150 | 152 |
|
|
151 | 153 |
|
|
152 | 154 |
|
|
153 | 155 |
|
|
154 | 156 | |
|
155 |
|
|
|
157 | if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) | |
|
156 | 158 | continue; |
|
157 | 159 | |
|
158 | 160 | #ifdef DT_REG |
@@ -190,11 +192,10 static PyObject *listdir(PyObject *self, | |||
|
190 | 192 | |
|
191 | 193 |
|
|
192 | 194 | |
|
193 |
|
|
|
195 | if (!name || !py_kind || !val) { | |
|
194 | 196 |
|
|
195 | 197 |
|
|
196 | 198 |
|
|
197 | ||
|
198 | 199 | goto bail; |
|
199 | 200 | } |
|
200 | 201 | |
@@ -210,14 +211,12 static PyObject *listdir(PyObject *self, | |||
|
210 | 211 | } |
|
211 | 212 | |
|
212 | 213 |
|
|
214 | size = PyList_Size(list); | |
|
215 | #ifdef AT_SYMLINK_NOFOLLOW | |
|
216 | dfd = dirfd(dir); | |
|
217 | #endif | |
|
213 | 218 | |
|
214 | 219 |
|
|
215 | ssize_t size = PyList_Size(list); | |
|
216 | ssize_t i; | |
|
217 | #ifdef AT_SYMLINK_NOFOLLOW | |
|
218 | int dfd = dirfd(dir); | |
|
219 | #endif | |
|
220 | ||
|
221 | 220 | for (i = 0; i < size; i++) { |
|
222 | 221 |
|
|
223 | 222 |
|
@@ -235,16 +234,17 static PyObject *listdir(PyObject *self, | |||
|
235 | 234 |
|
|
236 | 235 | struct listdir_stat *st; |
|
237 | 236 | |
|
238 |
if (ctor_args |
|
|
237 | if (!ctor_args) { | |
|
239 | 238 |
|
|
240 |
|
|
|
239 | if (!ctor_args) | |
|
241 | 240 | goto bail; |
|
242 | 241 | } |
|
243 | 242 | |
|
244 | 243 | st = (struct listdir_stat *) |
|
245 | 244 |
|
|
246 | 245 | ctor_args); |
|
247 | if (st == NULL) | |
|
246 | ||
|
247 | if (!st) | |
|
248 | 248 |
|
|
249 | 249 | #ifdef AT_SYMLINK_NOFOLLOW |
|
250 | 250 | ret = fstatat(dfd, name, &st->st, AT_SYMLINK_NOFOLLOW); |
@@ -277,14 +277,14 static PyObject *listdir(PyObject *self, | |||
|
277 | 277 | |
|
278 | 278 |
|
|
279 | 279 | py_kind = PyInt_FromLong(kind); |
|
280 |
if (py_kind |
|
|
280 | if (!py_kind) | |
|
281 | 281 |
|
|
282 | 282 | Py_XDECREF(Py_None); |
|
283 | 283 | PyTuple_SET_ITEM(elt, 1, py_kind); |
|
284 | 284 | } |
|
285 | 285 | |
|
286 | 286 |
|
|
287 |
if (py_st |
|
|
287 | if (!py_st) { | |
|
288 | 288 |
|
|
289 | 289 |
|
|
290 | 290 | } |
@@ -302,10 +302,10 done: | |||
|
302 | 302 |
|
|
303 | 303 |
|
|
304 | 304 |
|
|
305 | ||
|
306 | 305 |
|
|
307 | 306 | } |
|
308 | 307 | |
|
308 | ||
|
309 | 309 | static char osutil_doc[] = "Native operating system services."; |
|
310 | 310 | |
|
311 | 311 | static PyMethodDef methods[] = { |
General Comments 0
You need to be logged in to leave comments.
Login now