Open
Description
Describe the bug
wasmer fail to print the file size of hard link file.
Steps to reproduce
(1)The test case is :
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
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);
}
}
void fd_fdstat_get_00002_yBbmO(int fd) {
printf("Enter function fd_fdstat_get_00002_yBbmO\n");
int flags = fcntl(fd, F_GETFL);
if (flags == -1) {
printf("Error getting file descriptor flags\n");
return;
}
printf("File descriptor flags: %d\n", flags);
int access_mode = flags & O_ACCMODE;
if (access_mode == O_RDONLY) {
printf("Access mode: Read Only\n");
}
if (access_mode == O_WRONLY) {
printf("Access mode: Write Only\n");
}
if (access_mode == O_RDWR) {
printf("Access mode: Read/Write\n");
}
if (flags & O_TRUNC) {
printf("Flag: O_TRUNC\n");
}
if (flags & O_APPEND) {
printf("Flag: O_APPEND\n");
}
if (flags & O_CREAT) {
printf("Flag: O_CREAT\n");
}
if (flags & O_NONBLOCK) {
printf("Flag: Non-blocking\n");
}
if (flags & O_SYNC) {
printf("Flag: Synchronous Write\n");
}
if (flags & O_DSYNC) {
printf("Flag: Data Synchronization Write\n");
}
}
int main() {
int fd = get_fd("subdir_1/subdir_2/subdir_3/subdir_4/subfile_2", O_WRONLY);
if (fd == -1) {
return -1;
}
fd_fdstat_get_00002_yBbmO(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, subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 exists.)
wasmer run --dir=. test.wasm
Expected behavior
print:
Get file descriptor of file subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 succeed!
Enter function fd_fdstat_get_00002_yBbmO
File descriptor flags: 268435456
Access mode: Write Only
This is what wasmtime, WAMR and WasmEdge do.
Actual behavior
wasmer print:
Get file descriptor of file subdir_1/subdir_2/subdir_3/subdir_4/subfile_2 succeed!
Enter function fd_fdstat_get_00002_yBbmO
File descriptor flags: 335544320
Access mode: Read/Write
Additional context
Ubuntu 20.04
x86_64
wasmer-4.2.2