This is the mail archive of the
mailing list for the GCC project.
Re: libgfortran patch for fortran PR 18653
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: rth at redhat dot com
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 2 Dec 2004 10:00:25 -0800 (PST)
- Subject: 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
> 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);
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.