Re: [PATCH] rev: fix some issues

Chet Ramey <[email protected]> Fri, 8 May 2026 09:09:02 -0400
Newsgroups gmane.comp.shells.bash.bugs
Organization ITS, Case Western Reserve University
Message-ID <[email protected]>
On 5/7/26 4:55 PM, Duncan Roe wrote:

> The original code is correct. The effect of including this patch is that rev
> with no arguments is a no-op. rev with no arguments *should* read lines from
> standard input (fd 0).

You're both right. If fd 0 is closed for some reason when `rev' is invoked
with a filename argument, the open() will return file descriptor 0 and the
original code will leave it open. Since it's a builtin, the open file
descriptor will persist in the shell execution environment.

The usual fix is to use a flag that tells whether the file descriptor is
the inherited stdin or the result of open(). I added that yesterday.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc (application/pgp-signature, 203 B)
-----BEGIN PGP SIGNATURE-----

wmMEABEIACMWIQR8ATX7CIqvbGbGULm7WGnwZOp0qwUCaf3gbgUDAAAAAAAKCRC7WGnwZOp0qzsh
AJ4uHp8++w6FsjJAmHxUuPdDIAxVhACfeBuvBT9uwETIFXQFrQ95Q34URIw=
=c76b
-----END PGP SIGNATURE-----