+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.
char path[min(PATH_MAX, opp->file_len + 1)];
int mode;
int rwflag;
- int crflag;
+ int crflag, crflag2;
int fd;
int err;
}
#endif
- rwflag = 0;
-
switch (flags->action)
{
case ACTION_READ:
break;
case STATUS_UNKNOWN:
- case STATUS_SCRATCH:
- crflag = O_CREAT;
+ if (rwflag == O_RDONLY)
+ crflag = 0;
+ else
+ crflag = O_CREAT;
break;
case STATUS_REPLACE:
break;
default:
+ /* Note: STATUS_SCRATCH is handled by tempfile () and should
+ never be seen here. */
internal_error (&opp->common, "regular_file(): Bad status");
}
/* 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 */