Show More
@@ -172,29 +172,19 b' static PyObject *make_item(const WIN32_F' | |||
|
172 | 172 | kind, py_st); |
|
173 | 173 | } |
|
174 | 174 | |
|
175 | static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) | |
|
175 | static PyObject *_listdir(char *path, int plen, int wantstat, char *skip) | |
|
176 | 176 | { |
|
177 | 177 | PyObject *rval = NULL; /* initialize - return value */ |
|
178 | PyObject *statobj = NULL; /* initialize - optional arg */ | |
|
179 | 178 | PyObject *list; |
|
180 | 179 | HANDLE fh; |
|
181 | 180 | WIN32_FIND_DATAA fd; |
|
182 | char *path, *pattern, *skip = NULL; | |
|
183 | int plen, wantstat; | |
|
184 | ||
|
185 | static char *kwlist[] = {"path", "stat", "skip", NULL}; | |
|
186 | ||
|
187 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|Os:listdir", | |
|
188 | kwlist, &path, &plen, &statobj, &skip)) | |
|
189 | goto error_parse; | |
|
190 | ||
|
191 | wantstat = statobj && PyObject_IsTrue(statobj); | |
|
181 | char *pattern; | |
|
192 | 182 | |
|
193 | 183 | /* build the path + \* pattern string */ |
|
194 | 184 | pattern = malloc(plen+3); /* path + \* + \0 */ |
|
195 | 185 | if (!pattern) { |
|
196 | 186 | PyErr_NoMemory(); |
|
197 |
goto error_ |
|
|
187 | goto error_nomem; | |
|
198 | 188 | } |
|
199 | 189 | strcpy(pattern, path); |
|
200 | 190 | |
@@ -254,7 +244,7 b' error_list:' | |||
|
254 | 244 | FindClose(fh); |
|
255 | 245 | error_file: |
|
256 | 246 | free(pattern); |
|
257 |
error_ |
|
|
247 | error_nomem: | |
|
258 | 248 | return rval; |
|
259 | 249 | } |
|
260 | 250 | |
@@ -276,33 +266,27 b' int entkind(struct dirent *ent)' | |||
|
276 | 266 | return -1; |
|
277 | 267 | } |
|
278 | 268 | |
|
279 | static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) | |
|
269 | static PyObject *_listdir(char *path, int pathlen, int keepstat, char *skip) | |
|
280 | 270 | { |
|
281 | static char *kwlist[] = { "path", "stat", "skip", NULL }; | |
|
282 | PyObject *statflag = NULL, *list, *elem, *stat, *ret = NULL; | |
|
283 | char fullpath[PATH_MAX + 10], *path, *skip = NULL; | |
|
284 | int pathlen, keepstat, kind, dfd = -1, err; | |
|
271 | PyObject *list, *elem, *stat, *ret = NULL; | |
|
272 | char fullpath[PATH_MAX + 10]; | |
|
273 | int kind, dfd = -1, err; | |
|
285 | 274 | struct stat st; |
|
286 | 275 | struct dirent *ent; |
|
287 | 276 | DIR *dir; |
|
288 | 277 | |
|
289 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|Os:listdir", kwlist, | |
|
290 | &path, &pathlen, &statflag, &skip)) | |
|
291 | goto error_parse; | |
|
292 | ||
|
293 | 278 | if (pathlen >= PATH_MAX) { |
|
294 | 279 | PyErr_SetString(PyExc_ValueError, "path too long"); |
|
295 |
goto error_ |
|
|
280 | goto error_value; | |
|
296 | 281 | } |
|
297 | 282 | strncpy(fullpath, path, PATH_MAX); |
|
298 | 283 | fullpath[pathlen] = '/'; |
|
299 | keepstat = statflag && PyObject_IsTrue(statflag); | |
|
300 | 284 | |
|
301 | 285 | #ifdef AT_SYMLINK_NOFOLLOW |
|
302 | 286 | dfd = open(path, O_RDONLY); |
|
303 | 287 | if (dfd == -1) { |
|
304 | 288 | PyErr_SetFromErrnoWithFilename(PyExc_OSError, path); |
|
305 |
goto error_ |
|
|
289 | goto error_value; | |
|
306 | 290 | } |
|
307 | 291 | dir = fdopendir(dfd); |
|
308 | 292 | #else |
@@ -375,12 +359,36 b' error_dir:' | |||
|
375 | 359 | #ifdef AT_SYMLINK_NOFOLLOW |
|
376 | 360 | close(dfd); |
|
377 | 361 | #endif |
|
378 |
error_ |
|
|
362 | error_value: | |
|
379 | 363 | return ret; |
|
380 | 364 | } |
|
381 | 365 | |
|
382 | 366 | #endif /* ndef _WIN32 */ |
|
383 | 367 | |
|
368 | static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) | |
|
369 | { | |
|
370 | PyObject *statobj = NULL; /* initialize - optional arg */ | |
|
371 | PyObject *skipobj = NULL; /* initialize - optional arg */ | |
|
372 | char *path, *skip = NULL; | |
|
373 | int wantstat, plen; | |
|
374 | ||
|
375 | static char *kwlist[] = {"path", "stat", "skip", NULL}; | |
|
376 | ||
|
377 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s#|OO:listdir", | |
|
378 | kwlist, &path, &plen, &statobj, &skipobj)) | |
|
379 | return NULL; | |
|
380 | ||
|
381 | wantstat = statobj && PyObject_IsTrue(statobj); | |
|
382 | ||
|
383 | if (skipobj && skipobj != Py_None) { | |
|
384 | skip = PyString_AsString(skipobj); | |
|
385 | if (!skip) | |
|
386 | return NULL; | |
|
387 | } | |
|
388 | ||
|
389 | return _listdir(path, plen, wantstat, skip); | |
|
390 | } | |
|
391 | ||
|
384 | 392 | static char osutil_doc[] = "Native operating system services."; |
|
385 | 393 | |
|
386 | 394 | static PyMethodDef methods[] = { |
General Comments 0
You need to be logged in to leave comments.
Login now