|
From: | Paul Eggert |
Subject: | bug#18449: "cat x >> x" error even when x is empty |
Date: | Thu, 11 Sep 2014 08:52:17 -0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
Eric Blake wrote:
Testing for an empty file is enough of an additional special case over the existing check for same files that I don't think it is worth it.
It's a really cheap check, as a system call is needed only when the input and output files are the same, and even then it's only an lseek with SEEK_CUR so it's all in-memory. Plus, the POSIX 'cat' spec gives an example of using 'cat' to copy an empty regular file to itself, and (not unreasonably) says that should work.
As far as POSIX conformance goes, I don't think we need to worry about POSIXLY_CORRECT here. We'll get POSIX fixed instead. Eric has already started the ball rolling on that (thanks). Though the POSIX fix should involve updating its example -- and quite possibly POSIX should continue to allow catting an empty file to itself.
I installed the attached patch and am marking this as done. The 'cat' source code is simpler now, so that's a win anyway....
0001-cat-allow-copying-empty-files-to-themselves.patch
Description: Text document
[Prev in Thread] | Current Thread | [Next in Thread] |