summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-07-11 16:06:16 +1000
committerDamien George <damien.p.george@gmail.com>2018-07-11 16:06:16 +1000
commit3ab2f3fb2b807a49cf4835cfff7b5e5139a1da76 (patch)
treeb1c752e7b9393ff58421171d92be1f1a37b78176
parente2e22e3d7e29985579b2c91c639c71229422f349 (diff)
unix/modos: Convert dir-type to stat-type for file type in ilistdir.
Fixes issue #3931.
-rw-r--r--ports/unix/modos.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ports/unix/modos.c b/ports/unix/modos.c
index d99d0d62c..2c32cdd41 100644
--- a/ports/unix/modos.c
+++ b/ports/unix/modos.c
@@ -172,12 +172,24 @@ STATIC mp_obj_t listdir_next(mp_obj_t self_in) {
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
t->items[0] = mp_obj_new_str(dirent->d_name, strlen(dirent->d_name));
+
#ifdef _DIRENT_HAVE_D_TYPE
- t->items[1] = MP_OBJ_NEW_SMALL_INT(dirent->d_type);
+ #ifdef DTTOIF
+ t->items[1] = MP_OBJ_NEW_SMALL_INT(DTTOIF(dirent->d_type));
+ #else
+ if (dirent->d_type == DT_DIR) {
+ t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFDIR);
+ } else if (dirent->d_type == DT_REG) {
+ t->items[1] = MP_OBJ_NEW_SMALL_INT(MP_S_IFREG);
+ } else {
+ t->items[1] = MP_OBJ_NEW_SMALL_INT(dirent->d_type);
+ }
+ #endif
#else
// DT_UNKNOWN should have 0 value on any reasonable system
t->items[1] = MP_OBJ_NEW_SMALL_INT(0);
#endif
+
#ifdef _DIRENT_HAVE_D_INO
t->items[2] = MP_OBJ_NEW_SMALL_INT(dirent->d_ino);
#else