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

Function __syscall_dup3

system/lib/wasmfs/syscalls.cpp:52–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50using namespace wasmfs;
51
52int __syscall_dup3(int oldfd, int newfd, int flags) {
53 if (flags & ~O_CLOEXEC) {
54 return -EINVAL;
55 }
56 if (oldfd == newfd) {
57 return -EINVAL;
58 }
59
60 auto fileTable = wasmFS.getFileTable().locked();
61 auto oldOpenFile = fileTable.getEntry(oldfd);
62 if (!oldOpenFile) {
63 return -EBADF;
64 }
65 if (newfd < 0 || newfd >= WASMFS_FD_MAX) {
66 return -EBADF;
67 }
68
69 // If the file descriptor newfd was previously open, it will just be
70 // overwritten silently.
71 (void)fileTable.setEntry(newfd, oldOpenFile);
72 return newfd;
73}
74
75int __syscall_dup(int fd) {
76 auto fileTable = wasmFS.getFileTable().locked();

Callers

nothing calls this directly

Calls 3

getEntryMethod · 0.80
setEntryMethod · 0.80
lockedMethod · 0.45

Tested by

no test coverage detected