emscripten-core / emscripten-core/emscripten

realpath is not portable to windows for NODERAWFS

Open
#17,829 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.19 (a5f7b1c9a1c74a830bebedc122d204800ce8dff9)
clang version 16.0.0 (https://github.com/llvm/llvm-project 30171e76f0e5ea8037bc4d1450dd3e12af4d9938)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /home/rich/source/emsdk/upstream/bin

Building this c program:
```c
#include
#include
#include
#include
#include

int main(int argc, char *argv[])
{
struct dirent *pDirent;
DIR *pDir;

// Ensure correct argument count.

if (argc != 2)
{
printf("Usage: main \n");
return 1;
}

// Get the realpath
char cresolved_path[PATH_MAX];
char * res = realpath(argv[1], cresolved_path);
if (res == NULL) {
char error_buf[300] = {0};
strcpy(error_buf, strerror(errno));
printf("Cannot real path the directory '%s' with '%s'\n", argv[1], error_buf);
return -1;
}

return 0;
}
```
With `-s NODERAWFS` should generate a portable js/wasm combination.

It works fine on linux.

When I run this outputted wasm using node on windows, I get this:

```
PS C:\Users\aku91\source\repos\debugpyweb> node ..\realpath_c\main.js C:\Users\aku91\source\repos
Cannot real path the directory 'C:\Users\aku91\source\repos' with 'No such file or directory'
```

I _think_ the problem lies in the [realpath implementation](https://github.com/emscripten-core/emscripten/blob/main/system/lib/libc/musl/src/misc/realpath.c). It doesn't look like it would work on windows.

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.