bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: On darwin, diff <(echo ab) <(echo cd) does nothing


From: John.Cowan
Subject: Re: On darwin, diff <(echo ab) <(echo cd) does nothing
Date: Mon, 22 Aug 2005 01:43:45 -0400
User-agent: Mutt/1.4.2.1i

Paul Eggert scripsit:

> This is a semantic issue: should "diff X X" be required to read X
> twice, or should it be allowed to read X just once?  Similarly for
> "cmp X X".  John Cowan's point about "diff /dev/tty /dev/tty" also
> bears on this issue.  "diff - -" is similar: currently GNU diff
> outputs nothing even if standard input is a tty.

With the existing optimization, diff reads X zero times in that case.
As for "diff - -", the documentation is a little strange: it says that
"[a]s a special case, `diff - -' compares a copy of standard input
to itself."  But this is not actually what happens: the standard input
is not copied or even read.

> As far as I can see, POSIX requires the optimization in question.  For
> diff it says that "no output shall be produced if the files are
> identical" and for cmp it says that it "shall write no output if the
> files are the same".  However, since Solaris cmp and diff do not have
> the optimization I suppose Sun doesn't agree with this interpretation.

I think Posix neither requires nor prohibits the optimization.  I read
the text as meaning that no output is to be produced if the contents
of the files are identical, rather than if their names are identical.
In this case, "names" are combinations of inode attributes rather than
pathnames.  If the names of plain files or directories are identical,
so are their contents (assuming they are not being concurrently written),
so the optimization is safe in that case.

In any case, the Sun code is old pre-SysV code, and should be afforded
some respect if the Posix wording is truly ambiguous.  (The opengroup.org
server is semi-down right now.)

-- 
John Cowan  address@hidden  www.ccil.org/~cowan  www.reutershealth.com
If I have not seen as far as others, it is because giants were standing
on my shoulders.
        --Hal Abelson




reply via email to

[Prev in Thread] Current Thread [Next in Thread]