emscripten-core / emscripten-core/emscripten
WASMFS fdatasync(bad_fd) returns positive value instead of `-1`
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
**Version of emscripten/emsdk:**
```
5.0.6
```
POSIX: `fdatasync()` on an invalid fd must return `-1` with errno set. Under WASMFS where `-sWASMFS=1`, `fdatasync()` returns a positive value and leaves `errno = 0`.
**Failing command line in full:**
```
$ emcc -O0 -Wall -sWASMFS=1 fdatasync.c -o a.out.js
$ node a.out.js
fdatasync(9999): ret=8 errno=0
```
The same program on native Linux prints `fdatasync(9999): ret=-1 errno=9`. Default emcc builds also print `fdatasync(9999): ret=-1 errno=8`.
**Example code snippet:**
```c
#include
#include
#include
int main(void) {
errno = 0;
int r = fdatasync(9999);
printf("fdatasync(9999): ret=%d errno=%d\n", r, errno);
return (r == -1) ? 0 : 1;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.