On 03/23/2014 03:47 PM, Paul Eggert wrote: > Karl Berry wrote: >> It seems like it should either read stdin twice (probably too much >> trouble), or read stdin once and then abort when it can't be read again, >> or just abort immediately. Or something, just not success. > > I don't see why 'diff' should be prohibited from optimizing the case > 'diff A A'. 'diff' should be allowed to read 'A' just once (or even not > at all, which is what 'diff' actually does). '-' is just a special case > of this. POSIX states in XCU 1.4: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap01.html Unless otherwise stated, the use of multiple instances of '-' to mean standard input in a single command produces unspecified results. and its description for 'diff' does not place any other requirements on double '-', so we are free to behave however we want. I personally think that special-casing '-' to read stdin twice makes more sense, at least when fstat(0) says that stdin is not a regular file (the way that 'cat - -' behaves differently for stdin used twice). I agree with the optimization of not reading a file at all if we know the argument is not '-', or if the argument is '-' but fstat(0) says the file is regular. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org