emscripten-core / emscripten-core/emscripten

Deno's fs.openSync fails with O_RDONLY | O_CREAT

Open
#26,235 1 comment 0 reactions 0 assignees View on GitHub
engine: deno
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The following program works find under node and bun:

```
import { openSync, closeSync, constants } from "node:fs";

// Create or open a file for writing, creates if it doesn't exist
const fd = openSync("./log.txt", constants.O_WRONLY | constants.O_CREAT);
// ... operations
closeSync(fd);
```

But not under deno:

```
$ ~/.deno/bin/deno -A test.mjs
error: Uncaught (in promise) TypeError: creating or truncating a file requires write or append access
const fd = openSync("missing.txt", constants.O_RDONLY | constants.O_CREAT);
^
at openSync (ext:deno_node/_fs/_fs_open.ts:43:12)
at file:///usr/local/google/home/sbc/dev/wasm/emscripten/test.mjs:3:12
```

The C equivalent also seem to work fine, so I think maybe deno is wrong here?

```
#include
#include
#include

int main() {
int fd = open("missing.txt", O_RDONLY|O_CREAT, 0x777);
printf("%d\n", fd);
return 0;
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.