emscripten-core / emscripten-core/emscripten
open() ignores trailing slash on regular files (no ENOTDIR)
- 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 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:**
```c
#include
#include
#include
#include
#include
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;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.