diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-12-14 23:48:12 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-12-14 23:48:12 +0200 |
commit | d874702fe1e5822f8a3e1662657ac27d0b15bb68 (patch) | |
tree | 45fcdd6eea42ab8c6e6b324f96c785a12477ed9f /unix/mpconfigport.h | |
parent | 1a1cceaf6f42332aee3ab69d52488d7cd5f8fd30 (diff) | |
download | micropython-d874702fe1e5822f8a3e1662657ac27d0b15bb68.tar.gz micropython-d874702fe1e5822f8a3e1662657ac27d0b15bb68.zip |
unix/modos: Implement ilistdir().
ilistdir() returns iterator which yields triples of (name, type, ino)
where ino is inode number for entry's data, type of entry (file/dir/etc.),
and name of file/dir. listdir() can be easily implemented in terms of this
iterator (which is otherwise more efficient in terms of memory use and may
save expensive call to stat() for each returned entry).
CPython has os.scandir() which also returns an iterator, but it yields
more complex objects of DirEntry type. scandir() can also be easily
implemented in terms of ilistdir().
Diffstat (limited to 'unix/mpconfigport.h')
-rw-r--r-- | unix/mpconfigport.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/unix/mpconfigport.h b/unix/mpconfigport.h index ad75f5287e..5fd122e96e 100644 --- a/unix/mpconfigport.h +++ b/unix/mpconfigport.h @@ -250,3 +250,12 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj; #include <alloca.h> #endif #endif + +// From "man readdir": "Under glibc, programs can check for the availability +// of the fields [in struct dirent] not defined in POSIX.1 by testing whether +// the macros [...], _DIRENT_HAVE_D_TYPE are defined." +// Other libc's don't define it, but proactively assume that dirent->d_type +// is available on a modern *nix system. +#ifndef _DIRENT_HAVE_D_TYPE +#define _DIRENT_HAVE_D_TYPE (1) +#endif |