emscripten-core/emscripten

FS permission handling seems odd

Open

#14,866 opened on Aug 14, 2021

View on GitHub
 (2 comments) (0 reactions) (0 assignees)C++ (3,519 forks)batch import
help wanted

Repository metrics

Stars
 (27,361 stars)
PR merge metrics
 (Avg merge 19d 10h) (147 merged PRs in 30d)

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.

#include <assert.h>
#include <stdio.h>

#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

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