emscripten-core / emscripten-core/emscripten
WASMFS: FS_writeFile appends (should overwrite) if called multiple times
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Please include the following in your bug report:
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.49 (04a0cad4d4c9f5d62876821274d78cd0a52427af)
clang version 18.0.0 (https://github.com/llvm/llvm-project 269685545e439ad050b67740533c59f965cae955)
Target: wasm32-unknown-emscripten
Thread model: posix
```
**Failing command line in full:**
```bash
emcc -o main.js main.c -s WASMFS=1 -s FORCE_FILESYSTEM=1
```
```c
#include
#ifdef __EMSCRIPTEN__
#include
#else
#define EM_ASM(...)
#endif
int main(void) {
EM_ASM(
FS.writeFile("test.txt", "123\n");
FS.writeFile("test.txt", "456\n");
);
FILE *file = fopen("test.txt", "r");
if (file == NULL) return 1;
char buffer[100];
size_t bytesRead;
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
fwrite(buffer, 1, bytesRead, stdout);
}
fclose(file);
return 0;
}
```
With `WASMFS=1` outputs `123\n456\n` (wrong).
With `WASMFS=0` outputs `456\n` (correct).
Contributor guide
Assessment
This issue has not been assessed yet.