Skip to content

Commit ec782f6

Browse files
committed
Make seek work on /dev/null
Seeking `/dev/null` should work and do nothing instead of returning `EPIPE`. This fixes it.
1 parent 079e266 commit ec782f6

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/library_fs.js

+1
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ FS.staticInit();
13471347
FS.registerDevice(FS.makedev(1, 3), {
13481348
read: () => 0,
13491349
write: (stream, buffer, offset, length, pos) => length,
1350+
llseek: () => 0,
13501351
});
13511352
FS.mkdev('/dev/null', FS.makedev(1, 3));
13521353
// setup /dev/tty and /dev/tty1

test/other/test_seek_dev_null.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <unistd.h>
2+
#include <fcntl.h>
3+
#include <string.h>
4+
#include <errno.h>
5+
#include <stdio.h>
6+
7+
int main() {
8+
int fd = open("/dev/null", O_WRONLY);
9+
printf("fd: %d\n", fd);
10+
if (fd == -1) {
11+
printf("open failed: %s\n", strerror(errno));
12+
return 1;
13+
}
14+
int res = lseek(fd, 10, SEEK_CUR);
15+
printf("res: %d\n", res);
16+
if (res == -1) {
17+
printf("lseek failed: %s\n", strerror(errno));
18+
return 1;
19+
}
20+
return 0;
21+
}

test/other/test_seek_dev_null.out

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fd: 3
2+
res: 0

test/test_other.py

+3
Original file line numberDiff line numberDiff line change
@@ -15329,3 +15329,6 @@ def test_fp16(self, opts):
1532915329

1533015330
def test_embool(self):
1533115331
self.do_other_test('test_embool.c')
15332+
15333+
def test_seek_dev_null(self):
15334+
self.do_other_test('test_seek_dev_null.c')

0 commit comments

Comments
 (0)