tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: possible bug in fseek of buffered files shared between processes (example uses stdin)



On Tue 02 Nov 2021 at 03:48:36 -0700, Carlo Arenas wrote:
> the following works in Windows/Linux/macOS :
> 
>   $ printf "1\n2\n3\n" > i && ( head -1; head -1; cat ) < i && rm -f i
> 1
> 2
> 3
> 
> but only works in recent NetBSD if STDBUF0=U is set (which is not
> available in OpenBSD or other derivatives that are also affected (ex:
> AIX))

This can never work in the presence of buffering (which is likely
allowed by the C Standard, but I didn't look that up), because not all
input is seekable. This variant "fails" equally on Linux, MacOS and
NetBSD:

$ printf "1\n2\n3\n" | ( head -1; head -1; cat )
1
$

-Olaf.
-- 
___ "Buying carbon credits is a bit like a serial killer paying someone else to
\X/  have kids to make his activity cost neutral." -The BOFH    falu.nl@rhialto

Attachment: signature.asc
Description: PGP signature



Home | Main Index | Thread Index | Old Index