# HG changeset patch # User Matt Mackall # Date 1191887237 18000 # Node ID e760cb72c02ef159476cb225ab7f02c03e4dff5e # Parent 830f6e280c9045ea04fa0f8c79dc6eb0c7b655d4 osutil: simplify DT_REG support diff --git a/mercurial/osutil.c b/mercurial/osutil.c --- a/mercurial/osutil.c +++ b/mercurial/osutil.c @@ -206,37 +206,29 @@ static PyObject *listdir(PyObject *self, PyObject *name = NULL; PyObject *py_kind = NULL; PyObject *val = NULL; - unsigned char d_type; int kind = -1; if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) continue; #ifdef DT_REG - if (do_stat) - d_type = 0; - else - d_type = ent->d_type; + if (!do_stat) + switch (ent->d_type) { + case DT_REG: kind = S_IFREG; break; + case DT_DIR: kind = S_IFDIR; break; + case DT_LNK: kind = S_IFLNK; break; + case DT_BLK: kind = S_IFBLK; break; + case DT_CHR: kind = S_IFCHR; break; + case DT_FIFO: kind = S_IFIFO; break; + case DT_SOCK: kind = S_IFSOCK; break; + default: + all_kinds = 0; + break; + } #else - d_type = 0; + all_kinds = 0; #endif - switch (d_type) { -#ifdef DT_REG - case DT_REG: kind = S_IFREG; break; - case DT_DIR: kind = S_IFDIR; break; - case DT_LNK: kind = S_IFLNK; break; - case DT_BLK: kind = S_IFBLK; break; - case DT_CHR: kind = S_IFCHR; break; - case DT_FIFO: kind = S_IFIFO; break; - case DT_SOCK: kind = S_IFSOCK; break; -#endif - default: - if (all_kinds) - all_kinds = 0; - break; - } - name = PyString_FromString(ent->d_name); if (kind != -1) py_kind = PyInt_FromLong(kind);