Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions system/lib/libc/musl/src/unistd/getcwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ char *getcwd(char *buf, size_t size)
long ret = syscall(SYS_getcwd, buf, size);
if (ret < 0)
return 0;
#ifdef __EMSCRIPTEN__
// In upstream musl, `buf[0] != '/'` checks for Linux's `(unreachable)`
// prefix returned by the kernel's getcwd syscall. Emscripten's
// __syscall_getcwd never returns `(unreachable)` (it returns -ENOENT
// directly), and under NODERAWFS on Windows valid paths can start with
// a drive letter (e.g. `C:\...`) or UNC prefix (`\\...`). That is, the
// Emscripten change here is to get musl to work properly on Windows (which
// musl does not normally do).
if (ret == 0) {
#else
if (ret == 0 || buf[0] != '/') {
#endif
errno = ENOENT;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 270695,
"a.out.nodebug.wasm": 588110,
"total": 858805,
"a.out.nodebug.wasm": 588098,
"total": 858793,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
19 changes: 19 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -9753,6 +9753,7 @@ def test_noderawfs_disables_embedding(self):
self.assert_fail(base + ['--preload-file', 'somefile'], expected)
self.assert_fail(base + ['--embed-file', 'somefile'], expected)

@crossplatform
def test_noderawfs_access_abspath(self):
create_file('foo', 'bar')
create_file('access.c', r'''
Expand All @@ -9763,6 +9764,24 @@ def test_noderawfs_access_abspath(self):
''')
self.do_runf('access.c', cflags=['-sNODERAWFS'], args=[os.path.abspath('foo')])

@crossplatform
def test_noderawfs_getcwd(self):
create_file('getcwd.c', r'''
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>

int main() {
char buf[PATH_MAX];
char* cwd = getcwd(buf, sizeof(buf));
assert(cwd == buf);
printf("cwd: %s\n", cwd);
return 0;
}
''')
self.do_runf('getcwd.c', f'cwd: {os.getcwd()}\n', cflags=['-sNODERAWFS'])

def test_noderawfs_readfile_prerun(self):
create_file('foo', 'bar')
self.add_pre_run("console.log(FS.readFile('foo', { encoding: 'utf8' }));")
Expand Down
3 changes: 2 additions & 1 deletion test/unistd/unlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ void test() {
// Update: Removing cwd on Linux does not return EBUSY.
// WASMFS behaviour will match the native FS.
#ifndef __APPLE__
getcwd(buffer, sizeof(buffer));
char* cwd = getcwd(buffer, sizeof(buffer));
assert(cwd != NULL);
printf("CWD: %s\n", buffer);
err = rmdir(buffer);
assert(err == -1);
Expand Down
Loading