Skip to content

Commit 437140d

Browse files
authored
Make seek work on /dev/null (#22886)
Seeking `/dev/null` should work and do nothing instead of returning `EPIPE`. This fixes it.
1 parent 079e266 commit 437140d

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-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/test_files.c

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ void test_tempfiles() {
162162
char data[5] = { 10, 30, 20, 11, 88 };
163163
FILE *n = fopen("/dev/null", "w");
164164
printf("5 bytes to dev/null: %zu\n", fwrite(data, 1, 5, n));
165+
int res = fseek(n, 10, SEEK_CUR);
166+
printf("seek /dev/null: %d\n", res);
165167
fclose(n);
166168

167169
// Test file creation with O_TRUNC (regression test for #16784)

test/test_files.out

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ seeked=ata.
1212
seeked=ta.
1313
fscanfed: 10 - hello
1414
5 bytes to dev/null: 5
15+
seek /dev/null: 0
1516
ok.

0 commit comments

Comments
 (0)