Skip to content

Commit b2ced9d

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 ffeb761 commit b2ced9d

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
@@ -1348,6 +1348,7 @@ FS.staticInit();
13481348
FS.registerDevice(FS.makedev(1, 3), {
13491349
read: () => 0,
13501350
write: (stream, buffer, offset, length, pos) => length,
1351+
llseek: () => 0,
13511352
});
13521353
FS.mkdev('/dev/null', FS.makedev(1, 3));
13531354
// 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
@@ -15295,3 +15295,6 @@ def test_fp16(self, opts):
1529515295

1529615296
def test_embool(self):
1529715297
self.do_other_test('test_embool.c')
15298+
15299+
def test_seek_dev_null(self):
15300+
self.do_other_test('test_seek_dev_null.c')

0 commit comments

Comments
 (0)