diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2013-11-16 00:00:36 +0200 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2013-11-16 00:00:36 +0200 |
commit | 35f48a901dacbff644f8573553d2b1ca6d1b609c (patch) | |
tree | 285137952297d3a8123cac1f2509532a3cb644d6 /libgfortran | |
parent | c02065fca15d60c9d34ca18b5718a145c4571db7 (diff) | |
download | gcc-35f48a901dacbff644f8573553d2b1ca6d1b609c.zip gcc-35f48a901dacbff644f8573553d2b1ca6d1b609c.tar.gz gcc-35f48a901dacbff644f8573553d2b1ca6d1b609c.tar.bz2 |
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
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 8 | ||||
-rw-r--r-- | libgfortran/io/unix.c | 20 |
2 files changed, 21 insertions, 7 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 31a4fb5..c18391f1 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -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. diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index 8a84ae4..c2bc28a 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -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 */ |