You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/uio.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_read_00022_Ep05V(int fd) {
printf("Enter function fd_read_00022_Ep05V\n");
char buf1[1];
char buf2[1];
struct iovec iov[2];
ssize_t num_read;
iov[0].iov_base = buf1;
iov[0].iov_len = 1;
iov[1].iov_base = buf2;
iov[1].iov_len = 1;
num_read = readv(fd, iov, 2);
if (num_read == -1) {
printf("Error reading from file descriptor\n");
} else {
printf("Read %ld bytes using readv\n", num_read);
}
}
int main() {
int fd = get_fd("softfile_2", O_RDWR | O_TRUNC | O_CREAT);
if (fd == -1) {
return 1;
}
fd_read_00022_Ep05V(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, softfile_2 exists and softfile_2 is a softlink file points to subdir_1/subdir_4/subfile_2, subdir_1/subdir_4/subfile_2 exists and the file is 53 bytes.) wasmer run --dir=. test.wasm
Expected behavior
print:
Get file descriptor of file softfile_2 succeed!
Enter function fd_read_00022_Ep05V
Read 2 bytes using readv
Actual behavior
wasmer print:
Get file descriptor of file softfile_2 succeed!
Enter function fd_read_00022_Ep05V
Read 0 bytes using readv
First, the file size is 53, wasmer open the file with O_TRUNC, the file is expected to be truced to 0 bytes, however, by checking with command line, we found the file is not trunced and remains 53 bytes.
However, the buffer size is 2 bytes, but 0 bytes are read.
Additional context
Ubuntu 20.04
x86_64
wasmer-4.3.1
The text was updated successfully, but these errors were encountered:
Describe the bug
Read bytes bug.
Steps to reproduce
(1)The test case is :
(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, softfile_2 exists and softfile_2 is a softlink file points to subdir_1/subdir_4/subfile_2, subdir_1/subdir_4/subfile_2 exists and the file is 53 bytes.)
wasmer run --dir=. test.wasm
Expected behavior
print:
Actual behavior
wasmer print:
First, the file size is 53, wasmer open the file with O_TRUNC, the file is expected to be truced to 0 bytes, however, by checking with command line, we found the file is not trunced and remains 53 bytes.
However, the buffer size is 2 bytes, but 0 bytes are read.
Additional context
Ubuntu 20.04
x86_64
wasmer-4.3.1
The text was updated successfully, but these errors were encountered: