emscripten-core / emscripten-core/emscripten

FS permission handling seems odd

Open
#14,866 2 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

The following test code runs perfectly fine when compiled with clang and ran, but when ran with emscripten the `ftruncate` operation throws a `Permission error` instead of going through as expected.

```c
#include
#include

#include
#include
#include

int main() {
int fd = 0;
char filename[] = "XXXXXX";

// Test
assert((fd = mkstemp(filename)) >= 0);
assert(chmod(filename, 0) >= 0);
assert(ftruncate(fd, 69) >= 0);

// Cleanup
assert(close(fd) >= 0);
assert(remove(filename) >= 0);

printf("ok\n");
return 0;
}
```
Ran with
- `clang main.c -o testfs && ./testfs`
- `emcc main.c -s ENVIRONMENT=node -s MAIN_MODULE -o out.js && node out.js`

### Current behavior
Clang build prints ok, emcc build fails (assertion error at ftruncate)

### Expected behavior
Both should print "ok"

### Environment
OS: Arch Linux
clang version 12.0.1
emscripten version 2.0.26 (with clang 13.0.0)
node version 16.4.2

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.