Skip to content
Merged
3 changes: 3 additions & 0 deletions src/lib/libfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ FS.staticInit();
var getattr = FS.checkOpExists(node.node_ops.getattr, {{{ cDefs.EPERM }}});
return getattr(node);
},
fstat(fd) {
return FS.stat(FS.getStreamChecked(fd).path);
},
lstat(path) {
return FS.stat(path, true);
},
Expand Down
4 changes: 4 additions & 0 deletions src/lib/libnoderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ addToLibrary({
}
return stat;
},
fstat(fd) {
var stream = FS.getStreamChecked(fd);
return fs.fstatSync(stream.nfd);
},
statfsStream(stream) {
return fs.statfsSync(stream.path);
},
Expand Down
3 changes: 1 addition & 2 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,7 @@ var SyscallsLibrary = {
return SYSCALLS.writeStat(buf, FS.lstat(path));
},
__syscall_fstat64: (fd, buf) => {
var stream = SYSCALLS.getStreamFromFD(fd);
return SYSCALLS.writeStat(buf, FS.stat(stream.path));
return SYSCALLS.writeStat(buf, FS.fstat(fd));
},
__syscall_fchown32: (fd, owner, group) => {
FS.fchown(fd, owner, group);
Expand Down
20 changes: 20 additions & 0 deletions test/fs/test_stat_unnamed_file_descriptor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <assert.h>
#include "stdio.h"

int main() {
int fd = open("file.txt", O_RDWR | O_CREAT, 0666);
unlink("file.txt");
int res;
struct stat buf;
res = fstat(fd, &buf);
assert(res == 0);
assert(buf.st_atime > 1000000000);
res = fchmod(fd, 0777);
assert(res == 0);
res = ftruncate(fd, 10);
assert(res == 0);
printf("success\n");
}
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors1.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
129211
129218
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_ctors2.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
128623
128630
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
170879
170886
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_except_wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
144708
144715
Original file line number Diff line number Diff line change
@@ -1 +1 @@
142162
142169
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_mangle.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
232724
232731
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_noexcept.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
131774
131781
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_cxx_wasmfs.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
169181
169188
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_hello_O0.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15101
15113
2 changes: 1 addition & 1 deletion test/other/codesize/test_codesize_minimal_pthreads.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19394
19405
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15101
15113
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12182
12194
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.wasm.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15101
15113
9 changes: 9 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5842,6 +5842,15 @@ def test_fs_64bit(self):
self.set_setting('FORCE_FILESYSTEM')
self.do_runf('fs/test_64bit.c', 'success')

@crossplatform
@with_all_fs
def test_fs_stat_unnamed_file_descriptor(self):
noderawfs = '-DNODERAWFS' in self.emcc_args
wasmfs = self.get_setting('WASMFS')
if not (noderawfs or wasmfs):
self.skipTest('TODO: doesnt work in memfs or nodefs')
self.do_runf('fs/test_stat_unnamed_file_descriptor.c', 'success')

@requires_node
@crossplatform
@with_all_fs
Expand Down
Loading