equal
deleted
inserted
replaced
6 This software may be used and distributed according to the terms of |
6 This software may be used and distributed according to the terms of |
7 the GNU General Public License, incorporated herein by reference. |
7 the GNU General Public License, incorporated herein by reference. |
8 */ |
8 */ |
9 |
9 |
10 #define _ATFILE_SOURCE |
10 #define _ATFILE_SOURCE |
11 #define _LARGEFILE64_SOURCE |
|
12 #include <Python.h> |
11 #include <Python.h> |
13 #include <alloca.h> |
12 #include <alloca.h> |
14 #include <dirent.h> |
13 #include <dirent.h> |
15 #include <fcntl.h> |
14 #include <fcntl.h> |
16 #include <string.h> |
15 #include <string.h> |
111 } |
110 } |
112 |
111 |
113 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) |
112 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) |
114 { |
113 { |
115 DIR *dir = NULL; |
114 DIR *dir = NULL; |
116 struct dirent64 *ent; |
115 struct dirent *ent; |
117 PyObject *list = NULL; |
116 PyObject *list = NULL; |
118 PyObject *ctor_args = NULL; |
117 PyObject *ctor_args = NULL; |
119 int all_kinds = 1; |
118 int all_kinds = 1; |
120 char *full_path; |
119 char *full_path; |
121 int path_len; |
120 int path_len; |
144 |
143 |
145 full_path = alloca(path_len + PATH_MAX + 2); |
144 full_path = alloca(path_len + PATH_MAX + 2); |
146 memcpy(full_path, path, path_len); |
145 memcpy(full_path, path, path_len); |
147 full_path[path_len] = '/'; |
146 full_path[path_len] = '/'; |
148 |
147 |
149 while ((ent = readdir64(dir))) { |
148 while ((ent = readdir(dir))) { |
150 PyObject *name = NULL; |
149 PyObject *name = NULL; |
151 PyObject *py_kind = NULL; |
150 PyObject *py_kind = NULL; |
152 PyObject *val = NULL; |
151 PyObject *val = NULL; |
153 unsigned char d_type; |
152 unsigned char d_type; |
154 int kind = -1; |
153 int kind = -1; |