Il giorno gio 31 ott 2024 alle ore 08:09 Sergey Poznyakoff
<g...@gnu.org.ua> ha scritto:
>
> FWIW, the main question is actually: why
> lseek succeeded when reading from stdin?
>

For this question, I think that the ability to seek in a fd is not
stdin vs file, but more pipe vs file.
e.g.

tar -tf lib.tar # seekable
tar -t <lib.tar # seekable
cat lib.tar |tar -t # NOT seekable

This is detected in get_archive_status() by checking S_ISREG() or
S_ISBLK(), indeed lseek works on fd 0:

$ strace -elseek tar -t <lib.tar >/dev/null
lseek(0, 51200, SEEK_CUR)               = 61440
lseek(0, 81920, SEEK_CUR)               = 174080
lseek(0, 61440, SEEK_CUR)               = 245760
lseek(0, 10240, SEEK_CUR)               = 307200
lseek(0, 20480, SEEK_CUR)               = 378880
lseek(0, 61440, SEEK_CUR)               = 450560
lseek(0, 71680, SEEK_CUR)               = 532480
lseek(0, 163840, SEEK_CUR)              = 706560
lseek(0, 358400, SEEK_CUR)              = 1075200
+++ exited with 0 +++

Regards,
-- 
Matteo Croce

perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplay

Reply via email to