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

Function createDevice

src/lib/libwasmfs.js:391–411  ·  view source on GitHub ↗
(parent, name, input, output)

Source from the content-addressed store, hash-verified

389 wasmFSDevices[dev] = backendPointer;
390 },
391 createDevice(parent, name, input, output) {
392 if (typeof parent != 'string') {
393 // The old API allowed parents to be objects, which do not exist in WasmFS.
394 throw new Error("Only string paths are accepted");
395 }
396 var path = PATH.join2(parent, name);
397 var mode = FS_getMode(!!input, !!output);
398 FS.createDevice.major ??= 64;
399 var dev = FS.makedev(FS.createDevice.major++, 0);
400 // Create a fake device with a set of stream ops to emulate
401 // the old API's createDevice().
402 FS.registerDevice(dev, {
403 read(stream, buffer, offset, length, pos /* ignored */) {
404 var bytesRead = 0;
405 for (var i = 0; i < length; i++) {
406 var result;
407 try {
408 result = input();
409 } catch (e) {
410 throw new FS.ErrnoError({{{ cDefs.EIO }}});
411 }
412 if (result === undefined && bytesRead === 0) {
413 throw new FS.ErrnoError({{{ cDefs.EAGAIN }}});
414 }

Callers 1

libfs.jsFile · 0.70

Calls 1

FS_getModeFunction · 0.85

Tested by

no test coverage detected