Skip to content

open() ignores trailing slash on regular files (no ENOTDIR) #26710

@Ryan2026R

Description

@Ryan2026R

Version of emscripten/emsdk:

5.0.6

POSIX says a trailing slash implies directory access: open("file/", O_RDONLY) must fail with ENOTDIR when file is a regular file. Under MEMFS the call succeeds and returns a valid fd.

Failing command line in full:

$ emcc -O0 -Wall trailing.c -o a.out.js
$ node a.out.js
open(file/): fd=3 errno=0

The same program on native Linux prints open(file/): fd=-1 errno=20.

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/file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
    write(fd, "hello", 5); close(fd);

    errno = 0;
    fd = open("/tmp/xsv_test/file.txt/", O_RDONLY); // trailing slash
    printf("open(file/): fd=%d errno=%d\n", fd, errno);
    return (fd < 0) ? 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