Skip to content

Commit 5f77c71

Browse files
authored
WasmFS JS API: Implement llseek (#19601)
1 parent a303ebd commit 5f77c71

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ jobs:
532532
wasmfs.test_unistd_links_memfs
533533
wasmfs.test_fcntl_open
534534
wasmfs.test_fs_js_api
535+
wasmfs.test_fs_llseek
535536
wasmfs.test_freetype"
536537
test-wasm2js1:
537538
executor: bionic

emcc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,6 +2343,7 @@ def phase_linker_setup(options, state, newargs):
23432343
'_wasmfs_chmod',
23442344
'_wasmfs_fchmod',
23452345
'_wasmfs_lchmod',
2346+
'_wasmfs_llseek',
23462347
'_wasmfs_identify',
23472348
'_wasmfs_readdir_start',
23482349
'_wasmfs_readdir_get',

src/library_wasmfs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ FS.createPreloadedFile = FS_createPreloadedFile;
327327
}));
328328
},
329329
// TODO: syncfs
330-
// TODO: llseek
330+
llseek: (stream, offset, whence) => {
331+
return FS.handleError(__wasmfs_llseek(stream.fd, {{{ splitI64('offset') }}}, whence));
332+
}
331333
// TODO: ioctl
332334

333335
#endif

system/lib/wasmfs/js_api.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ int _wasmfs_lchmod(char* path, mode_t mode) {
181181
return __syscall_fchmodat(AT_FDCWD, (intptr_t)path, mode, AT_SYMLINK_NOFOLLOW);
182182
}
183183

184+
int _wasmfs_llseek(int fd, off_t offset, int whence) {
185+
__wasi_filesize_t newOffset;
186+
int err = __wasi_fd_seek(fd, offset, whence, &newOffset);
187+
if (err > 0) {
188+
return -err;
189+
}
190+
return newOffset;
191+
}
192+
184193
int _wasmfs_rename(char* oldpath, char* newpath) {
185194
return __syscall_renameat(AT_FDCWD, (intptr_t)oldpath, AT_FDCWD, (intptr_t)newpath);
186195
};

0 commit comments

Comments
 (0)