Open
Description
Describe the bug
Read directory failed.
Steps to reproduce
(1)The test case is :
#include <stdio.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
void fd_readdir_00001_sYQM0(int fd) {
printf("Enter function fd_readdir_00001_sYQM0\n");
DIR *directory;
struct dirent *entry;
directory = fdopendir(fd);
if (directory == NULL) {
printf("fdopendir failed.\n");
return;
}
while ((entry = readdir(directory)) != NULL) {
printf("Get dir content:%s\n", entry->d_name);
}
printf("Print dir content finished.\n");
}
int get_fd(const char *filename, int flags) {
int fd = open(filename, flags);
if (fd == -1) {
printf("Get file descriptor of file %s failed!\n", filename);
return -1;
} else {
printf("Get file descriptor of file %s succeed!\n", filename);
return fd;
}
}
void closebyfd(int fd) {
if (close(fd) == -1) {
printf("Close the file %d by descriptor failed!\n", fd);
}
}
int main() {
int fd = get_fd("subdir_3", O_RDONLY | O_DIRECTORY);
if (fd == -1) {
return 1;
}
fd_readdir_00001_sYQM0(fd);
closebyfd(fd);
return 0;
}
(2)compile to wasm:./wasi-sdk-21.0/bin/clang --target=wasm32-unkown-wasi --sysroot=./wasi-sdk-21.0/share/wasi-sysroot test.c -o test.wasm
(3)Running wasm:
(Before run the Wasm file, directory subdir_3 exists.
Change the permission of subdir_3 to 0600 before executing the Wasm file.)
wasmer run --dir=. test.wasm
Expected behavior
print:
Get file descriptor of file subdir_3 succeed!
Enter function fd_readdir_00001_sYQM0
Get dir content:subfile_2
Get dir content:.
Get dir content:..
Get dir content:subfile_1
Get dir content:subdir_2
Print dir content finished.
And this is what WAMR and WasmEdge do.
Actual behavior
wasmer print:
Get file descriptor of file subdir_3 succeed!
Enter function fd_readdir_00001_sYQM0
fdopendir failed.
Additional context
Ubuntu 20.04
x86_64
wasmer-4.2.2