Skip to content

Commit f3f36d5

Browse files
committed
Make fstat work on file descriptor with no name
1 parent 06cebfc commit f3f36d5

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/library_syscall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ var SyscallsLibrary = {
680680
},
681681
__syscall_fstat64: (fd, buf) => {
682682
var stream = SYSCALLS.getStreamFromFD(fd);
683-
return SYSCALLS.doStat(FS.stat, stream.path, buf);
683+
return SYSCALLS.doStat(stream.node.node_ops.getattr, stream.node, buf);
684684
},
685685
__syscall_fchown32: (fd, owner, group) => {
686686
FS.fchown(fd, owner, group);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <fcntl.h>
2+
#include <unistd.h>
3+
#include <sys/stat.h>
4+
#include <assert.h>
5+
#include "stdio.h"
6+
7+
int main() {
8+
int fd = open("file.txt", O_RDWR | O_CREAT, 0666);
9+
unlink("file.txt");
10+
int res;
11+
struct stat buf;
12+
res = fstat(fd, &buf);
13+
assert(res == 0);
14+
assert(buf.st_atime > 1000000000);
15+
printf("success\n");
16+
}

test/test_core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5921,6 +5921,11 @@ def test_fs_64bit(self):
59215921
self.set_setting('FORCE_FILESYSTEM')
59225922
self.do_runf('fs/test_64bit.c', 'success')
59235923

5924+
def test_fs_stat_unnamed_file_descriptor(self):
5925+
if self.get_setting('WASMFS'):
5926+
self.set_setting('FORCE_FILESYSTEM')
5927+
self.do_runf('fs/test_stat_unnamed_file_descriptor.c', 'success')
5928+
59245929
def test_sigalrm(self):
59255930
self.do_runf('test_sigalrm.c', 'Received alarm!')
59265931
self.set_setting('EXIT_RUNTIME')

0 commit comments

Comments
 (0)