Skip to content

WASMFS fdatasync(bad_fd) returns positive value instead of -1 #26713

@hly2019

Description

@hly2019

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:

#include <unistd.h>
#include <stdio.h>
#include <errno.h>

int main(void) {
    errno = 0;
    int r = fdatasync(9999);
    printf("fdatasync(9999): ret=%d errno=%d\n", r, errno);
    return (r == -1) ? 0 : 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions