Open
Description
Describe the bug
Read bytes bug.
Steps to reproduce
(1)The test case is :
#include <stdio.h>
#include <unistd.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_seek_00192_fOSeD(int fd) {
printf("Enter function fd_seek_00192_fOSeD\n");
off_t offset = lseek(fd, 460, SEEK_END);
if (offset == -1) {
printf("lseek failed\n");
} else {
printf("lseek success, new offset is: %ld\n", offset);
}
}
int main() {
int fd = get_fd("subfile_1", O_RDWR | O_CREAT);
if (fd == -1) {
return 1;
}
fd_seek_00192_fOSeD(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, subfile_1 exists and the file size is 29.)
wasmer run --dir=. test.wasm
Expected behavior
print:
Get file descriptor of file subfile_1 succeed!
Enter function fd_seek_00192_fOSeD
lseek success, new offset is: 489
This is what wasmtime, WAMR and WasmEdge do.
Actual behavior
wasmer print:
Get file descriptor of file subfile_1 succeed!
Enter function fd_seek_00192_fOSeD
lseek success, new offset is: 0
The seek parameter is SEEK_END in the C program, and the offset is 460. Thus, the new offset is expected to by set from the end of the file. That is to say, the new offset is expected to be 29(filesize) + 460 = 489.
However, the new offset set in wasmer is 0.
Additional context
Ubuntu 20.04
x86_64
wasmer-4.3.1