MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / getPath

Function getPath

system/lib/wasmfs/emscripten.cpp:28–52  ·  view source on GitHub ↗

Given an fd, returns the string path that the fd refers to. TODO: full error handling TODO: maybe make this a public API, as it is useful for debugging

Source from the content-addressed store, hash-verified

26// TODO: full error handling
27// TODO: maybe make this a public API, as it is useful for debugging
28std::string getPath(int fd) {
29 auto fileTable = wasmfs::wasmFS.getFileTable().locked();
30
31 auto openFile = fileTable.getEntry(fd);
32 if (!openFile) {
33 return "!";
34 }
35
36 auto curr = openFile->locked().getFile();
37 std::string result = "";
38 while (curr != wasmfs::wasmFS.getRootDirectory()) {
39 auto parent = curr->locked().getParent();
40 // Check if the parent exists. The parent may not exist if curr was
41 // unlinked.
42 if (!parent) {
43 return "?/" + result;
44 }
45
46 auto parentDir = parent->dynCast<wasmfs::Directory>();
47 auto name = parentDir->locked().getName(curr);
48 result = '/' + name + result;
49 curr = parentDir;
50 }
51 return result;
52}
53
54} // namespace wasmfs
55

Calls 6

getEntryMethod · 0.80
getRootDirectoryMethod · 0.80
getParentMethod · 0.80
lockedMethod · 0.45
getFileMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected