emscripten-core/emscripten

FS permission handling seems odd

Open

#14 866 ouverte le 14 août 2021

Voir sur GitHub
 (2 commentaires) (0 réactions) (0 assignés)C++ (3 519 forks)batch import
help wanted

Métriques du dépôt

Stars
 (27 361 stars)
Métriques de merge PR
 (Merge moyen 19j 10h) (147 PRs mergées en 30 j)

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

Guide contributeur