Version of emscripten/emsdk:
POSIX: write() on a file descriptor opened O_RDONLY should return -1. It seems that the default JS-FS does this correctly; but under WASMFS (-sWASMFS=1) the write succeeds.
Failing command line in full:
$ emcc -O0 -Wall -sWASMFS=1 write_rdonly.c -o a.out.js
$ node a.out.js
write(RDONLY fd): ret=1 errno=0
The same program on native Linux prints write(RDONLY fd): ret=-1 errno=9.
Example code snippet:
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
int main(void) {
mkdir("/tmp/xsv_test", 0755);
int fd = open("/tmp/xsv_test/f.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
write(fd, "x", 1); close(fd);
fd = open("/tmp/xsv_test/f.txt", O_RDONLY);
errno = 0;
ssize_t r = write(fd, "y", 1);
printf("write(RDONLY fd): ret=%zd errno=%d\n", r, errno);
close(fd);
return (r < 0) ? 0 : 1;
}
Version of emscripten/emsdk:
POSIX:
write()on a file descriptor openedO_RDONLYshould return-1. It seems that the default JS-FS does this correctly; but under WASMFS (-sWASMFS=1) the write succeeds.Failing command line in full:
The same program on native Linux prints
write(RDONLY fd): ret=-1 errno=9.Example code snippet: