Open
Description
Describe the bug
Read directory failed.
Steps to reproduce
(1)The test case is :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/uio.h>
#include <fcntl.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_write_00019_WOtrt(int fd) {
printf("Enter function fd_write_00019_WOtrt\n");
struct iovec iov[2];
iov[0].iov_base = "v0AXE";
iov[0].iov_len = 5;
iov[1].iov_base = "v0AXE";
iov[1].iov_len = 5;
off_t offset = lseek(fd, 0, SEEK_CUR);
printf("File current offset before write: %lld\n", (long long)offset);
ssize_t numBytes = writev(fd, iov, 2);
offset = lseek(fd, 0, SEEK_CUR);
printf("File current offset after write: %lld\n", (long long)offset);
if (numBytes == -1) {
printf("Write to file descriptor failed!\n");
} else {
printf("Write to file descriptor successful. Number of bytes written: %zd\n", numBytes);
}
}
int main() {
int fd = get_fd("subdir_1/subfile_1", O_WRONLY | O_APPEND);
if (fd == -1) {
return -1;
}
fd_write_00019_WOtrt(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, file subdir_1/subfile_1 exists, and the file size is 45.)
wasmer run --dir=. test.wasm
Expected behavior
print:
Get file descriptor of file subdir_1/subfile_1 succeed!
Enter function fd_write_00019_WOtrt
File current offset before write: 0
File current offset after write: 55
Write to file descriptor successful. Number of bytes written: 10
And this is what wasmtime, WAMR and WasmEdge do.
Actual behavior
wasmer print:
Get file descriptor of file subdir_1/subfile_1 succeed!
Enter function fd_write_00019_WOtrt
File current offset before write: 0
File current offset after write: 10
Write to file descriptor successful. Number of bytes written: 10
Although wasmer print offset after write is 10, the file size after writing is 55, it is written from the end of the file. Thus, the offset is expected to be 55 rather than 10.
Additional context
Ubuntu 20.04
x86_64
wasmer-4.2.2