This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch,libgfortran] PR45723 opening /dev/null for appending writes fails


On 09/20/2010 09:56 PM, Steve Kargl wrote:
On Mon, Sep 20, 2010 at 07:54:11PM -0700, Jerry DeLisle wrote:
Hi,

This patch is simple. Test case attached.

Regression tested on x86-64.

OK for trunk?


Is the file size guaranteed to be 0 for all non-seekable files on all operating systems supported by gfortran? If someone is stupid enough to open /dev/null for append, then he should be prepared to suffer the consequence.


You will notice the patch does nothing that presumes anything about the file, seekable or not.


All that patch is doing is not seeking if the length is zero or less. The filesize function being used will return a value less then zero for a few error conditions but in this case I simply chose to ignore it. So, if the file length happens to be zero, there is no need to seek. If that happens to work for /dev/null on some systems, no harm done.

From the typical man page:

"Data written to a null or zero special file is discarded." So my thinking, it should not matter "how" the file is opened if it is going to be discarded anyway. I suppose a user may find it useful during development of a program to write data to /dev/null, for example during trial runs where you would normally append, but for testing, do not want to keep growing the file. Who knows, not my place to question why someone might want to do this. It was suggested by one of our more valued testors. That was enough for me.

OK for trunk. :)

Jerry


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]