mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-02-21 05:12:40 +08:00
When file status is unknown, don't set O_CREAT when opening read-only.
2013-11-15 Janne Blomqvist <jb@gcc.gnu.org> Jerry DeLisle <jvdelisle@gcc.gnu.org> PR fortran/59108 * io/unix.c (regular_file): Don't set O_CREAT when opening a file read-only with unknown status. Mask out O_CREAT when falling back to opening read-only if ACTION= is not set and read-write fails. Co-Authored-By: Jerry DeLisle <jvdelisle@gcc.gnu.org> From-SVN: r204864
This commit is contained in:
parent
c02065fca1
commit
35f48a901d
@ -1,3 +1,11 @@
|
||||
2013-11-15 Janne Blomqvist <jb@gcc.gnu.org>
|
||||
Jerry DeLisle <jvdelisle@gcc.gnu.org>
|
||||
|
||||
PR fortran/59108
|
||||
* io/unix.c (regular_file): Don't set O_CREAT when opening a file
|
||||
read-only with unknown status. Mask out O_CREAT when falling back
|
||||
to opening read-only if ACTION= is not set and read-write fails.
|
||||
|
||||
2013-11-15 Steve Ellcey <sellcey@mips.com>
|
||||
|
||||
* configure.ac: Do not define HAVE_STRTOLD.
|
||||
|
@ -1245,7 +1245,7 @@ regular_file (st_parameter_open *opp, unit_flags *flags)
|
||||
char path[min(PATH_MAX, opp->file_len + 1)];
|
||||
int mode;
|
||||
int rwflag;
|
||||
int crflag;
|
||||
int crflag, crflag2;
|
||||
int fd;
|
||||
int err;
|
||||
|
||||
@ -1297,8 +1297,6 @@ regular_file (st_parameter_open *opp, unit_flags *flags)
|
||||
}
|
||||
#endif
|
||||
|
||||
rwflag = 0;
|
||||
|
||||
switch (flags->action)
|
||||
{
|
||||
case ACTION_READ:
|
||||
@ -1329,8 +1327,10 @@ regular_file (st_parameter_open *opp, unit_flags *flags)
|
||||
break;
|
||||
|
||||
case STATUS_UNKNOWN:
|
||||
case STATUS_SCRATCH:
|
||||
crflag = O_CREAT;
|
||||
if (rwflag == O_RDONLY)
|
||||
crflag = 0;
|
||||
else
|
||||
crflag = O_CREAT;
|
||||
break;
|
||||
|
||||
case STATUS_REPLACE:
|
||||
@ -1338,6 +1338,8 @@ regular_file (st_parameter_open *opp, unit_flags *flags)
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Note: STATUS_SCRATCH is handled by tempfile () and should
|
||||
never be seen here. */
|
||||
internal_error (&opp->common, "regular_file(): Bad status");
|
||||
}
|
||||
|
||||
@ -1366,14 +1368,18 @@ regular_file (st_parameter_open *opp, unit_flags *flags)
|
||||
|
||||
/* retry for read-only access */
|
||||
rwflag = O_RDONLY;
|
||||
fd = open (path, rwflag | crflag, mode);
|
||||
if (flags->status == STATUS_UNKNOWN)
|
||||
crflag2 = crflag & ~(O_CREAT);
|
||||
else
|
||||
crflag2 = crflag;
|
||||
fd = open (path, rwflag | crflag2, mode);
|
||||
if (fd >=0)
|
||||
{
|
||||
flags->action = ACTION_READ;
|
||||
return fd; /* success */
|
||||
}
|
||||
|
||||
if (errno != EACCES)
|
||||
if (errno != EACCES && errno != ENOENT)
|
||||
return fd; /* failure */
|
||||
|
||||
/* retry for write-only access */
|
||||
|
Loading…
Reference in New Issue
Block a user