This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: libgfortran patch for fortran PR 18653


On Wed, 1 Dec 2004 11:54:52 -0800, Richard Henderson wrote:
>
> On Wed, Dec 01, 2004 at 10:43:10AM -0800, Steve Ellcey wrote:
> > !       if (file_exists() && file_is_readable() && !file_is_writable())
> > !         flags->action = ACTION_READ;
> > !       else if (file_exists() && file_is_writable() && !file_is_readable())
> > !         flags->action = ACTION_WRITE;
> > !       else
> > !         flags->action = ACTION_READWRITE;
> 
> It would seem a shame to use 6 system calls to figure out one piece
> of information.

Yes it is, the main reason I looked at this approach was to avoid having
to create an ACTION_DEFAULT so that I could tell the difference between
a user-specified ACTION_READWRITE and a defaulted ACTION_READWRITE where
the user actually didn't specify any specific action.  Maybe I can still
avoid that.

> Additionally, there's a classical race condition here between the 
> access and the open system call.  Ideally, you'd attempt the open
> with the most permissive options (readwrite), and then fall back
> to read or write if that fails.  But in all cases you use the error
> from the open system call as the test, rather than a prior access
> system call.

This is probably the better way to do it, it just requires more changes
to the internal library interfaces which I had been hoping to avoid.

Would anyone care to comment on this idea:

Change the open_external prototype from:

	stream *open_external (unit_action action, unit_status status);
to:
	stream *open_external (unit_flags * flags, int default_action);

This way I could initially set flags->action to ACTION_READWRITE in
new_unit but if the user didn't really specify anything I would set
default_action to true and that would tell open_external that it was OK
to change flags->action to ACTION_READ or ACTION_WRITE if the initial
open failed with ACTION_READWRITE.  That way I don't need an
ACTION_DEFAULT and I have a way to set action to what was actually used
in the open command.

The interface for regular_file (called from open_external) would need
the same change since it is regular_file that actually does the open.

Comments?

Steve Ellcey
sje@cup.hp.com


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