Skip to content

errno is not set properly on failure #10157

@TuckWa

Description

@TuckWa

We've noticed this when switching to using the llvm-wasm backend. (currently using emscripten 1.39.4)

Here's a small testcase:

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

int main()
{
    int fd = 0;
    printf("errno is %d\n", errno);
    fd = open("doesnotexist.txt", O_RDONLY);
    printf("fd is %d, errno is %d\n", fd, errno);
    return 0;
}

When compiled with gcc, I get the expected "no such file":
errno is 0
fd is -1, errno is 2

When using emcc and running in a browser, I keep seeing errno being set to 44 "Channel number out of range"
(compiled with emcc testopen.c -o testopen.html)
errno is 0
fd is -1, errno is 44

I'm not sure if this is indicative of some other problem, but it's obviously causing some issues for us since moving off of fastcomp.

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