WebAssembly/wasi-libc

Unexpected return of `getcwd` if host system is Windows

RotateMe opened this issue · 1 comments

The following code behaves differently if the host-system is Windows or Linux:

#include "iostream"
#include "unistd.h"

int main(int, char **)
{
    char cwd[999] = {'\0'};
    auto cwdReturn = getcwd(cwd, sizeof(cwd));
    std::cout << "Current working dir via getcwd(): " << cwd << std::endl;
    std::cout << "Return was a nullpointer?: " << (cwdReturn == nullptr) << std::endl;

    return 0;
}

While the value of cwd is correct in both cases, the return is a nullptr for the Windows/Node setting, but has a valid value in the Ubuntu/Node setting. I would expect it to have a valid return in both cases.

The code was compiled with the following flags (copy-pasted from the CMake code)

        "-pthread"
        "-sNODERAWFS=1"
        "-sALLOW_MEMORY_GROWTH=1"
        "-sENVIRONMENT=worker"
        "-sEXPORTED_RUNTIME_METHODS=['ENV']"
        "-sEXPORT_NAME=${PROJECT_NAME}"
        "-sINITIAL_MEMORY=128mb"
        "-sLLD_REPORT_UNDEFINED"
        "-sMALLOC=mimalloc"
        "-sMODULARIZE=1"
        "-sPTHREAD_POOL_SIZE=8"
        "-sSTACK_SIZE=2MB"

The significance here is that this seems to be the only issue in preventing to use gtest in emscripten builds (see https://github.com/google/googletest/blob/main/googletest/src/gtest-internal-inl.h#L688 and https://github.com/google/googletest/blob/main/googletest/src/gtest-filepath.cc#L101 )

Emscripten does not use wasi-libc so this is likely the wrong place to file this bug. Can you re-open in the emscripten project?