Skip to content

Commit 67dc2ae

Browse files
authored
Fix readdir for posix (#3339)
This PR fixes a readir for posix. readdir is not working correctly in rust. The current WAMR's readdir implementation for posix is, if readdir returns 0, it will exit with an error. But posix readdir returns 0 at the end of the directory. To handle this correctly, if readdir returns 0, it should only raise an error if errno has changed. We can reproduce it with the following rust code: ```rust use std::fs; fn main() { let entries = fs::read_dir(".").unwrap(); for entry in entries { println!("read_dir:{:?}", entry); } } ```
1 parent e7a8b3e commit 67dc2ae

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/shared/platform/common/posix/posix_file.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,12 @@ os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry,
920920

921921
if (dent == NULL) {
922922
*d_name = NULL;
923-
return convert_errno(errno);
923+
if (errno != 0) {
924+
return convert_errno(errno);
925+
}
926+
else {
927+
return 0;
928+
}
924929
}
925930

926931
long offset = (__wasi_dircookie_t)telldir(dir_stream);

0 commit comments

Comments
 (0)