comparison mercurial/osutil.c @ 5426:e760cb72c02e

osutil: simplify DT_REG support
author Matt Mackall <mpm@selenic.com>
date Mon, 08 Oct 2007 18:47:17 -0500
parents 830f6e280c90
children dae6188e8c9e
comparison
equal deleted inserted replaced
5425:830f6e280c90 5426:e760cb72c02e
204 204
205 for (ent = readdir(dir); ent; ent = readdir(dir)) { 205 for (ent = readdir(dir); ent; ent = readdir(dir)) {
206 PyObject *name = NULL; 206 PyObject *name = NULL;
207 PyObject *py_kind = NULL; 207 PyObject *py_kind = NULL;
208 PyObject *val = NULL; 208 PyObject *val = NULL;
209 unsigned char d_type;
210 int kind = -1; 209 int kind = -1;
211 210
212 if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) 211 if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
213 continue; 212 continue;
214 213
215 #ifdef DT_REG 214 #ifdef DT_REG
216 if (do_stat) 215 if (!do_stat)
217 d_type = 0; 216 switch (ent->d_type) {
218 else 217 case DT_REG: kind = S_IFREG; break;
219 d_type = ent->d_type; 218 case DT_DIR: kind = S_IFDIR; break;
219 case DT_LNK: kind = S_IFLNK; break;
220 case DT_BLK: kind = S_IFBLK; break;
221 case DT_CHR: kind = S_IFCHR; break;
222 case DT_FIFO: kind = S_IFIFO; break;
223 case DT_SOCK: kind = S_IFSOCK; break;
224 default:
225 all_kinds = 0;
226 break;
227 }
220 #else 228 #else
221 d_type = 0; 229 all_kinds = 0;
222 #endif 230 #endif
223
224 switch (d_type) {
225 #ifdef DT_REG
226 case DT_REG: kind = S_IFREG; break;
227 case DT_DIR: kind = S_IFDIR; break;
228 case DT_LNK: kind = S_IFLNK; break;
229 case DT_BLK: kind = S_IFBLK; break;
230 case DT_CHR: kind = S_IFCHR; break;
231 case DT_FIFO: kind = S_IFIFO; break;
232 case DT_SOCK: kind = S_IFSOCK; break;
233 #endif
234 default:
235 if (all_kinds)
236 all_kinds = 0;
237 break;
238 }
239 231
240 name = PyString_FromString(ent->d_name); 232 name = PyString_FromString(ent->d_name);
241 if (kind != -1) 233 if (kind != -1)
242 py_kind = PyInt_FromLong(kind); 234 py_kind = PyInt_FromLong(kind);
243 else { 235 else {