Эх сурвалжийг харах

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);
    }
}
```
komasayuki 1 жил өмнө
parent
commit
67dc2ae0b2

+ 6 - 1
core/shared/platform/common/posix/posix_file.c

@@ -920,7 +920,12 @@ os_readdir(os_dir_stream dir_stream, __wasi_dirent_t *entry,
 
     if (dent == NULL) {
         *d_name = NULL;
-        return convert_errno(errno);
+        if (errno != 0) {
+            return convert_errno(errno);
+        }
+        else {
+            return 0;
+        }
     }
 
     long offset = (__wasi_dircookie_t)telldir(dir_stream);