-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathlibwasmfs.js
633 lines (592 loc) · 22 KB
/
libwasmfs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/**
* @license
* Copyright 2022 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
addToLibrary({
$MEMFS__deps: ['wasmfs_create_memory_backend'],
$MEMFS: {
createBackend(opts) {
return _wasmfs_create_memory_backend();
}
},
$wasmFSPreloadedFiles: [],
$wasmFSPreloadedDirs: [],
// We must note when preloading has been "flushed", that is, the time at which
// WasmFS has started up and read the preloaded data. After that time, no more
// data needs to be preloaded (and it would be invalid to do so, as any
// further additions to wasmFSPreloadedFiles|Dirs would be ignored).
$wasmFSPreloadingFlushed: false,
$wasmFSDevices: {},
$wasmFSDeviceStreams: {},
$FS__deps: [
'$MEMFS',
'$wasmFSPreloadedFiles',
'$wasmFSPreloadedDirs',
'$wasmFSPreloadingFlushed',
'$PATH',
'$stringToUTF8OnStack',
'$withStackSave',
'$readI53FromI64',
'$readI53FromU64',
'$FS_createDataFile',
'$FS_createPreloadedFile',
'$FS_getMode',
// For FS.readFile
'$UTF8ArrayToString',
#if FORCE_FILESYSTEM || INCLUDE_FULL_LIBRARY // FULL_LIBRARY will include JS
// code in other places that ends
// up requiring all of our code
// here.
'$FS_modeStringToFlags',
'$FS_create',
'$FS_mknod',
'$FS_mkdir',
'$FS_mkdirTree',
'$FS_writeFile',
'$FS_unlink',
#if LibraryManager.has('libicasefs.js')
'$ICASEFS',
#endif
#if LibraryManager.has('libnodefs.js')
'$NODEFS',
#endif
#if LibraryManager.has('libopfs.js')
'$OPFS',
#endif
#if LibraryManager.has('libjsfilefs.js')
'$JSFILEFS',
#endif
#if LibraryManager.has('libfetchfs.js')
'$FETCHFS',
#endif
'malloc',
'free',
'wasmfs_create_jsimpl_backend',
'$wasmFS$backends',
'$wasmFSDevices',
'$wasmFSDeviceStreams'
#endif
],
$FS : {
ErrnoError: class extends Error {
name = 'ErrnoError';
message = 'FS error';
constructor(code) {
super();
this.errno = code
}
},
handleError(returnValue) {
// Assume errors correspond to negative returnValues
// since some functions like _wasmfs_open() return positive
// numbers on success (some callers of this function may need to negate the parameter).
if (returnValue < 0) {
throw new FS.ErrnoError(-returnValue);
}
return returnValue;
},
createDataFile(parent, name, fileData, canRead, canWrite, canOwn) {
FS_createDataFile(parent, name, fileData, canRead, canWrite, canOwn);
},
createPath(parent, path, canRead, canWrite) {
// Cache file path directory names.
var parts = path.split('/').reverse();
while (parts.length) {
var part = parts.pop();
if (!part) continue;
var current = PATH.join2(parent, part);
if (!wasmFSPreloadingFlushed) {
wasmFSPreloadedDirs.push({parentPath: parent, childName: part});
} else {
try {
FS.mkdir(current);
} catch (e) {
if (e.errno != {{{ cDefs.EEXIST }}}) throw e;
}
}
parent = current;
}
return current;
},
createPreloadedFile(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) {
return FS_createPreloadedFile(parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish);
},
#if hasExportedSymbol('_wasmfs_read_file') // Support the JS function exactly
// when the __wasmfs_* function is
// present to be called (otherwise,
// we'd error anyhow). This depends
// on other code including the
// __wasmfs_* method properly.
readFile(path, opts = {}) {
opts.encoding = opts.encoding || 'binary';
if (opts.encoding !== 'utf8' && opts.encoding !== 'binary') {
throw new Error('Invalid encoding type "' + opts.encoding + '"');
}
// Copy the file into a JS buffer on the heap.
var sp = stackSave();
var buf = __wasmfs_read_file(stringToUTF8OnStack(path));
stackRestore(sp);
// The signed integer length resides in the first 8 bytes of the buffer.
var length = {{{ makeGetValue('buf', '0', 'i53') }}};
// Default return type is binary.
// The buffer contents exist 8 bytes after the returned pointer.
var ret = new Uint8Array(HEAPU8.subarray(buf + 8, buf + 8 + length));
if (opts.encoding === 'utf8') {
ret = UTF8ArrayToString(ret);
}
return ret;
},
#endif
#if hasExportedSymbol('_wasmfs_get_cwd') // Similar to readFile, above.
cwd: () => UTF8ToString(__wasmfs_get_cwd()),
#endif
#if FORCE_FILESYSTEM || INCLUDE_FULL_LIBRARY // see comment above
// Full JS API support
analyzePath(path) {
// TODO: Consider simplifying this API, which for now matches the JS FS.
var exists = !!FS.findObject(path);
return {
exists,
object: {
contents: exists ? FS.readFile(path) : null
}
};
},
// libc methods
mkdir: (path, mode) => FS_mkdir(path, mode),
mkdirTree: (path, mode) => FS_mkdirTree(path, mode),
rmdir: (path) => FS.handleError(
withStackSave(() => __wasmfs_rmdir(stringToUTF8OnStack(path)))
),
open: (path, flags, mode = 0o666) => withStackSave(() => {
flags = typeof flags == 'string' ? FS_modeStringToFlags(flags) : flags;
var buffer = stringToUTF8OnStack(path);
var fd = FS.handleError(__wasmfs_open(buffer, flags, mode));
return { fd : fd };
}),
create: (path, mode) => FS_create(path, mode),
close: (stream) => FS.handleError(-__wasmfs_close(stream.fd)),
unlink: (path) => FS_unlink(path),
chdir: (path) => withStackSave(() => {
var buffer = stringToUTF8OnStack(path);
return __wasmfs_chdir(buffer);
}),
read(stream, buffer, offset, length, position) {
var seeking = typeof position != 'undefined';
var dataBuffer = _malloc(length);
var bytesRead;
if (seeking) {
bytesRead = __wasmfs_pread(stream.fd, dataBuffer, length, {{{ splitI64('position') }}});
} else {
bytesRead = __wasmfs_read(stream.fd, dataBuffer, length);
}
bytesRead = FS.handleError(bytesRead);
for (var i = 0; i < length; i++) {
buffer[offset + i] = {{{ makeGetValue('dataBuffer', 'i', 'i8')}}}
}
_free(dataBuffer);
return bytesRead;
},
// Note that canOwn is an optimization that we ignore for now in WasmFS.
write(stream, buffer, offset, length, position, canOwn) {
var seeking = typeof position != 'undefined';
var dataBuffer = _malloc(length);
for (var i = 0; i < length; i++) {
{{{ makeSetValue('dataBuffer', 'i', 'buffer[offset + i]', 'i8') }}};
}
var bytesRead;
if (seeking) {
bytesRead = __wasmfs_pwrite(stream.fd, dataBuffer, length, {{{ splitI64('position') }}});
} else {
bytesRead = __wasmfs_write(stream.fd, dataBuffer, length);
}
bytesRead = FS.handleError(bytesRead);
_free(dataBuffer);
return bytesRead;
},
allocate(stream, offset, length) {
return FS.handleError(__wasmfs_allocate(stream.fd, {{{ splitI64('offset') }}}, {{{ splitI64('length') }}}));
},
writeFile: (path, data) => FS_writeFile(path, data),
mmap: (stream, length, offset, prot, flags) => {
var buf = FS.handleError(__wasmfs_mmap(length, prot, flags, stream.fd, {{{ splitI64('offset') }}}));
return { ptr: buf, allocated: true };
},
// offset is passed to msync to maintain backwards compatibility with the legacy JS API but is not used by WasmFS.
msync: (stream, bufferPtr, offset, length, mmapFlags) => {
assert(offset === 0);
// TODO: assert that stream has the fd corresponding to the mapped buffer (bufferPtr).
return FS.handleError(__wasmfs_msync(bufferPtr, length, mmapFlags));
},
munmap: (addr, length) => (
FS.handleError(__wasmfs_munmap(addr, length))
),
symlink: (target, linkpath) => withStackSave(() => (
__wasmfs_symlink(stringToUTF8OnStack(target), stringToUTF8OnStack(linkpath))
)),
readlink(path) {
var readBuffer = FS.handleError(withStackSave(() => __wasmfs_readlink(stringToUTF8OnStack(path))));
return UTF8ToString(readBuffer);
},
statBufToObject(statBuf) {
// i53/u53 are enough for times and ino in practice.
return {
dev: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_dev, "u32") }}},
mode: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_mode, "u32") }}},
nlink: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_nlink, "u32") }}},
uid: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_uid, "u32") }}},
gid: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_gid, "u32") }}},
rdev: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_rdev, "u32") }}},
size: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_size, "i53") }}},
blksize: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_blksize, "u32") }}},
blocks: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_blocks, "u32") }}},
atime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_atim.tv_sec, "i53") }}},
mtime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_mtim.tv_sec, "i53") }}},
ctime: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ctim.tv_sec, "i53") }}},
ino: {{{ makeGetValue('statBuf', C_STRUCTS.stat.st_ino, "u53") }}}
}
},
stat(path) {
var statBuf = _malloc({{{ C_STRUCTS.stat.__size__ }}});
FS.handleError(withStackSave(() =>
__wasmfs_stat(stringToUTF8OnStack(path), statBuf)
));
var stats = FS.statBufToObject(statBuf);
_free(statBuf);
return stats;
},
lstat(path) {
var statBuf = _malloc({{{ C_STRUCTS.stat.__size__ }}});
FS.handleError(withStackSave(() =>
__wasmfs_lstat(stringToUTF8OnStack(path), statBuf)
));
var stats = FS.statBufToObject(statBuf);
_free(statBuf);
return stats;
},
chmod(path, mode) {
return FS.handleError(withStackSave(() => {
var buffer = stringToUTF8OnStack(path);
return __wasmfs_chmod(buffer, mode);
}));
},
lchmod(path, mode) {
return FS.handleError(withStackSave(() => {
var buffer = stringToUTF8OnStack(path);
return __wasmfs_lchmod(buffer, mode);
}));
},
fchmod(fd, mode) {
return FS.handleError(__wasmfs_fchmod(fd, mode));
},
utime: (path, atime, mtime) => (
FS.handleError(withStackSave(() => (
__wasmfs_utime(stringToUTF8OnStack(path), atime, mtime)
)))
),
truncate(path, len) {
return FS.handleError(withStackSave(() => (__wasmfs_truncate(stringToUTF8OnStack(path), {{{ splitI64('len') }}}))));
},
ftruncate(fd, len) {
return FS.handleError(__wasmfs_ftruncate(fd, {{{ splitI64('len') }}}));
},
findObject(path) {
var result = withStackSave(() => __wasmfs_identify(stringToUTF8OnStack(path)));
if (result == {{{ cDefs.ENOENT }}}) {
return null;
}
return {
isFolder: result == {{{ cDefs.EISDIR }}},
isDevice: false, // TODO: wasmfs support for devices
};
},
readdir: (path) => withStackSave(() => {
var pathBuffer = stringToUTF8OnStack(path);
var entries = [];
var state = __wasmfs_readdir_start(pathBuffer);
if (!state) {
// TODO: The old FS threw an ErrnoError here.
throw new Error("No such directory");
}
var entry;
while (entry = __wasmfs_readdir_get(state)) {
entries.push(UTF8ToString(entry));
}
__wasmfs_readdir_finish(state);
return entries;
}),
mount: (type, opts, mountpoint) => {
#if ASSERTIONS
if (typeof type == 'string') {
// The filesystem was not included, and instead we have an error
// message stored in the variable.
throw type;
}
#endif
var backendPointer = type.createBackend(opts);
return FS.handleError(withStackSave(() => _wasmfs_mount(stringToUTF8OnStack(mountpoint), backendPointer)));
},
unmount: (mountpoint) => (
FS.handleError(withStackSave(() => _wasmfs_unmount(stringToUTF8OnStack(mountpoint))))
),
// TODO: lookup
mknod: (path, mode, dev) => FS_mknod(path, mode, dev),
makedev: (ma, mi) => ((ma) << 8 | (mi)),
registerDevice(dev, ops) {
var backendPointer = _wasmfs_create_jsimpl_backend();
var definedOps = {
userRead: ops.read,
userWrite: ops.write,
allocFile: (file) => {
wasmFSDeviceStreams[file] = {}
},
freeFile: (file) => {
wasmFSDeviceStreams[file] = undefined;
},
getSize: (file) => {},
// Devices cannot be resized.
setSize: (file, size) => 0,
read: (file, buffer, length, offset) => {
var bufferArray = Module.HEAP8.subarray(buffer, buffer + length);
try {
var bytesRead = definedOps.userRead(wasmFSDeviceStreams[file], bufferArray, 0, length, offset);
} catch (e) {
return -e.errno;
}
Module.HEAP8.set(bufferArray, buffer);
return bytesRead;
},
write: (file, buffer, length, offset) => {
var bufferArray = Module.HEAP8.subarray(buffer, buffer + length);
try {
var bytesWritten = definedOps.userWrite(wasmFSDeviceStreams[file], bufferArray, 0, length, offset);
} catch (e) {
return -e.errno;
}
Module.HEAP8.set(bufferArray, buffer);
return bytesWritten;
},
};
wasmFS$backends[backendPointer] = definedOps;
wasmFSDevices[dev] = backendPointer;
},
createDevice(parent, name, input, output) {
if (typeof parent != 'string') {
// The old API allowed parents to be objects, which do not exist in WasmFS.
throw new Error("Only string paths are accepted");
}
var path = PATH.join2(parent, name);
var mode = FS_getMode(!!input, !!output);
FS.createDevice.major ??= 64;
var dev = FS.makedev(FS.createDevice.major++, 0);
// Create a fake device with a set of stream ops to emulate
// the old API's createDevice().
FS.registerDevice(dev, {
read(stream, buffer, offset, length, pos /* ignored */) {
var bytesRead = 0;
for (var i = 0; i < length; i++) {
var result;
try {
result = input();
} catch (e) {
throw new FS.ErrnoError({{{ cDefs.EIO }}});
}
if (result === undefined && bytesRead === 0) {
throw new FS.ErrnoError({{{ cDefs.EAGAIN }}});
}
if (result === null || result === undefined) break;
bytesRead++;
buffer[offset+i] = result;
}
return bytesRead;
},
write(stream, buffer, offset, length, pos) {
for (var i = 0; i < length; i++) {
try {
output(buffer[offset+i]);
} catch (e) {
throw new FS.ErrnoError({{{ cDefs.EIO }}});
}
}
return i;
}
});
return FS.mkdev(path, mode, dev);
},
// mode is an optional argument, which will be set to 0666 if not passed in.
mkdev(path, mode, dev) {
if (typeof dev === 'undefined') {
dev = mode;
mode = 0o666;
}
var deviceBackend = wasmFSDevices[dev];
if (!deviceBackend) {
throw new Error("Invalid device ID.");
}
return FS.handleError(withStackSave(() => (
_wasmfs_create_file(stringToUTF8OnStack(path), mode, deviceBackend)
)));
},
rename(oldPath, newPath) {
return FS.handleError(withStackSave(() => {
var oldPathBuffer = stringToUTF8OnStack(oldPath);
var newPathBuffer = stringToUTF8OnStack(newPath);
return __wasmfs_rename(oldPathBuffer, newPathBuffer);
}));
},
// TODO: syncfs
llseek(stream, offset, whence) {
return FS.handleError(__wasmfs_llseek(stream.fd, {{{ splitI64('offset') }}}, whence));
}
// TODO: ioctl
#endif
},
// Split-out FS.* methods. These are split out for code size reasons, so that
// we can include the ones we need on demand, rather than put them all on the
// main FS object. As a result the entire FS object is not needed if you just
// need some specific FS_* operations. When the FS object is present, it calls
// into those FS_* methods as needed.
//
// In contrast, the old JS FS (libfs.js) does the opposite: it puts all
// things on the FS object, and copies them to FS_* methods for use from JS
// library code. Given that the JS FS is implemented entirely in JS, that
// makes sense there (as almost all that FS object ends up needed anyhow all
// the time).
$FS_createDataFile__deps: [
'$wasmFSPreloadingFlushed', '$wasmFSPreloadedFiles',
'$FS_create', '$FS_writeFile',
],
$FS_createDataFile: (parent, name, fileData, canRead, canWrite, canOwn) => {
var pathName = name ? parent + '/' + name : parent;
var mode = FS_getMode(canRead, canWrite);
if (!wasmFSPreloadingFlushed) {
// WasmFS code in the wasm is not ready to be called yet. Cache the
// files we want to create here in JS, and WasmFS will read them
// later.
wasmFSPreloadedFiles.push({pathName, fileData, mode});
} else {
// WasmFS is already running, so create the file normally.
FS_create(pathName, mode);
FS_writeFile(pathName, fileData);
}
},
$FS_mknod__deps: ['_wasmfs_mknod'],
$FS_mknod: (path, mode, dev) => FS.handleError(withStackSave(() => {
var pathBuffer = stringToUTF8OnStack(path);
return __wasmfs_mknod(pathBuffer, mode, dev);
})),
$FS_create__deps: ['$FS_mknod'],
// Default settings copied from the legacy JS FS API.
$FS_create: (path, mode = 0o666) => {
mode &= {{{ cDefs.S_IALLUGO }}};
mode |= {{{ cDefs.S_IFREG }}};
return FS_mknod(path, mode, 0);
},
$FS_writeFile__deps: ['_wasmfs_write_file', '$stackSave', '$stackRestore'],
$FS_writeFile: (path, data) => {
var sp = stackSave();
var pathBuffer = stringToUTF8OnStack(path);
if (typeof data == 'string') {
var buf = new Uint8Array(lengthBytesUTF8(data) + 1);
var actualNumBytes = stringToUTF8Array(data, buf, 0, buf.length);
data = buf.slice(0, actualNumBytes);
}
var dataBuffer = _malloc(data.length);
#if ASSERTIONS
assert(dataBuffer);
#endif
for (var i = 0; i < data.length; i++) {
{{{ makeSetValue('dataBuffer', 'i', 'data[i]', 'i8') }}};
}
var ret = __wasmfs_write_file(pathBuffer, dataBuffer, data.length);
_free(dataBuffer);
stackRestore(sp);
return ret;
},
$FS_mkdir__deps: ['_wasmfs_mkdir'],
$FS_mkdir: (path, mode = 0o777) => FS.handleError(withStackSave(() => {
var buffer = stringToUTF8OnStack(path);
return __wasmfs_mkdir(buffer, mode);
})),
$FS_mkdirTree__docs: `
/**
* @param {number=} mode Optionally, the mode to create in. Uses mkdir's
* default if not set.
*/`,
$FS_mkdirTree__deps: ['$FS_mkdir'],
$FS_mkdirTree: (path, mode) => {
var dirs = path.split('/');
var d = '';
for (var i = 0; i < dirs.length; ++i) {
if (!dirs[i]) continue;
d += '/' + dirs[i];
try {
FS_mkdir(d, mode);
} catch(e) {
if (e.errno != {{{ cDefs.EEXIST }}}) throw e;
}
}
},
$FS_unlink__deps: ['_wasmfs_unlink'],
$FS_unlink: (path) => withStackSave(() => {
var buffer = stringToUTF8OnStack(path);
return __wasmfs_unlink(buffer);
}),
// Wasm access calls.
_wasmfs_get_num_preloaded_files__deps: [
'$wasmFSPreloadedFiles',
'$wasmFSPreloadingFlushed'],
_wasmfs_get_num_preloaded_files: () => {
// When this method is called from WasmFS it means that we are about to
// flush all the preloaded data, so mark that. (There is no call that
// occurs at the end of that flushing, which would be more natural, but it
// is fine to mark the flushing here as during the flushing itself no user
// code can run, so nothing will check whether we have flushed or not.)
wasmFSPreloadingFlushed = true;
return wasmFSPreloadedFiles.length;
},
_wasmfs_get_num_preloaded_dirs__deps: ['$wasmFSPreloadedDirs'],
_wasmfs_get_num_preloaded_dirs: () => wasmFSPreloadedDirs.length,
_wasmfs_get_preloaded_file_mode: (index) => wasmFSPreloadedFiles[index].mode,
_wasmfs_get_preloaded_parent_path: (index, parentPathBuffer) => {
var s = wasmFSPreloadedDirs[index].parentPath;
var len = lengthBytesUTF8(s) + 1;
stringToUTF8(s, parentPathBuffer, len);
},
_wasmfs_get_preloaded_child_path: (index, childNameBuffer) => {
var s = wasmFSPreloadedDirs[index].childName;
var len = lengthBytesUTF8(s) + 1;
stringToUTF8(s, childNameBuffer, len);
},
_wasmfs_get_preloaded_path_name__deps: ['$lengthBytesUTF8', '$stringToUTF8'],
_wasmfs_get_preloaded_path_name: (index, fileNameBuffer) => {
var s = wasmFSPreloadedFiles[index].pathName;
var len = lengthBytesUTF8(s) + 1;
stringToUTF8(s, fileNameBuffer, len);
},
_wasmfs_get_preloaded_file_size: (index) =>
wasmFSPreloadedFiles[index].fileData.length,
_wasmfs_copy_preloaded_file_data: (index, buffer) =>
HEAPU8.set(wasmFSPreloadedFiles[index].fileData, buffer),
_wasmfs_thread_utils_heartbeat__deps: ['emscripten_proxy_execute_queue'],
_wasmfs_thread_utils_heartbeat: (queue) => {
var intervalID =
setInterval(() => {
if (ABORT) {
clearInterval(intervalID);
} else {
_emscripten_proxy_execute_queue(queue);
}
}, 50);
},
_wasmfs_stdin_get_char__deps: ['$FS_stdin_getChar'],
_wasmfs_stdin_get_char: () => {
// Return the read character, or -1 to indicate EOF.
var c = FS_stdin_getChar();
if (typeof c === 'number') {
return c;
}
return -1;
}
});