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

Function __syscall_ioctl

system/lib/wasmfs/syscalls.cpp:1316–1364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1314}
1315
1316int __syscall_ioctl(int fd, int request, ...) {
1317 auto openFile = wasmFS.getFileTable().locked().getEntry(fd);
1318 if (!openFile) {
1319 return -EBADF;
1320 }
1321
1322 va_list args;
1323 va_start(args, request);
1324 void* argp = va_arg(args, void*);
1325 va_end(args);
1326
1327 auto openHandle = openFile->locked();
1328 auto file = openHandle.getFile();
1329
1330 if (request == FIONREAD) {
1331 off_t size = file->locked().getSize();
1332 if (size < 0) {
1333 return (int)size;
1334 }
1335 if (file->isSeekable()) {
1336 size -= openHandle.getPosition();
1337 }
1338 *static_cast<int*>(argp) = static_cast<int>(size);
1339 return 0;
1340 }
1341
1342 if (!isTTY(file)) {
1343 return -ENOTTY;
1344 }
1345 // TODO: Full TTY support. For now this is limited, and matches the old FS.
1346 switch (request) {
1347 case TCGETA:
1348 case TCGETS:
1349 case TCSETA:
1350 case TCSETAW:
1351 case TCSETAF:
1352 case TCSETS:
1353 case TCSETSW:
1354 case TCSETSF:
1355 case TIOCGWINSZ:
1356 case TIOCSWINSZ: {
1357 // TTY operations that we do nothing for anyhow can just be ignored.
1358 return 0;
1359 }
1360 default: {
1361 return -EINVAL; // not supported
1362 }
1363 }
1364}
1365
1366int __syscall_pipe2(int fd[2], int flags) {
1367 auto* fds = (__wasi_fd_t*)fd;

Callers

nothing calls this directly

Calls 7

isTTYFunction · 0.85
getEntryMethod · 0.80
isSeekableMethod · 0.80
getPositionMethod · 0.80
lockedMethod · 0.45
getFileMethod · 0.45
getSizeMethod · 0.45

Tested by

no test coverage detected