##// END OF EJS Templates
osutil: improve portability...
Matt Mackall -
r5457:7372b6bb default
parent child Browse files
Show More
@@ -7,9 +7,7 b''
7 7 the GNU General Public License, incorporated herein by reference.
8 8 */
9 9
10 #define _ATFILE_SOURCE
11 10 #include <Python.h>
12 #include <alloca.h>
13 11 #include <dirent.h>
14 12 #include <fcntl.h>
15 13 #include <string.h>
@@ -101,18 +99,6 b' static PyTypeObject listdir_stat_type = '
101 99 listdir_stat_new, /* tp_new */
102 100 };
103 101
104 static inline int mode_to_kind(int mode)
105 {
106 if (S_ISREG(mode)) return S_IFREG;
107 if (S_ISDIR(mode)) return S_IFDIR;
108 if (S_ISLNK(mode)) return S_IFLNK;
109 if (S_ISBLK(mode)) return S_IFBLK;
110 if (S_ISCHR(mode)) return S_IFCHR;
111 if (S_ISFIFO(mode)) return S_IFIFO;
112 if (S_ISSOCK(mode)) return S_IFSOCK;
113 return mode;
114 }
115
116 102 static PyObject *listfiles(PyObject *list, DIR *dir,
117 103 int keep_stat, int *need_stat)
118 104 {
@@ -187,9 +173,6 b' static PyObject *statfiles(PyObject *lis'
187 173 int ret;
188 174 ssize_t i;
189 175 ssize_t size = PyList_Size(list);
190 #ifdef AT_SYMLINK_NOFOLLOW
191 int dfd = dirfd(dir);
192 #endif
193 176
194 177 for (i = 0; i < size; i++) {
195 178 PyObject *elt = PyList_GetItem(list, i);
@@ -213,17 +196,29 b' static PyObject *statfiles(PyObject *lis'
213 196 PyTuple_SET_ITEM(elt, 2, py_st);
214 197 }
215 198
216 #ifdef AT_SYMLINK_NOFOLLOW
217 ret = fstatat(dfd, name, stp, AT_SYMLINK_NOFOLLOW);
218 #else
219 199 ret = lstat(path, stp);
220 #endif
221 200 if (ret == -1)
222 201 return PyErr_SetFromErrnoWithFilename(PyExc_OSError,
223 202 path);
224 203
225 if (kind == -1)
226 kind = mode_to_kind(stp->st_mode);
204 if (kind == -1) {
205 if (S_ISREG(stp->st_mode))
206 kind = S_IFREG;
207 else if (S_ISDIR(stp->st_mode))
208 kind = S_IFDIR;
209 else if (S_ISLNK(stp->st_mode))
210 kind = S_IFLNK;
211 else if (S_ISBLK(stp->st_mode))
212 kind = S_IFBLK;
213 else if (S_ISCHR(stp->st_mode))
214 kind = S_IFCHR;
215 else if (S_ISFIFO(stp->st_mode))
216 kind = S_IFIFO;
217 else if (S_ISSOCK(stp->st_mode))
218 kind = S_IFSOCK;
219 else
220 kind = stp->st_mode;
221 }
227 222
228 223 if (py_kind == Py_None && kind != -1) {
229 224 py_kind = PyInt_FromLong(kind);
General Comments 0
You need to be logged in to leave comments. Login now