+2015-03-11 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/65200
+ * gfortran.texi: Document behavior when opening files without
+ explicit ACTION= specifier.
+
2015-03-10 Paul Thomas <pault@gcc.gnu.org>
PR fortran/65024
* Internal representation of LOGICAL variables::
* Thread-safety of the runtime library::
* Data consistency and durability::
+* Files opened without an explicit ACTION= specifier::
@end menu
also force cache validation and flushing dirty data and metadata.
+@node Files opened without an explicit ACTION= specifier
+@section Files opened without an explicit ACTION= specifier
+@cindex open, action
+
+The Fortran standard says that if an @code{OPEN} statement is executed
+without an explicit @code{ACTION=} specifier, the default value is
+processor dependent. GNU Fortran behaves as follows:
+
+@enumerate
+@item Attempt to open the file with @code{ACTION='READWRITE'}
+@item If that fails, try to open with @code{ACTION='READ'}
+@item If that fails, try to open with @code{ACTION='WRITE'}
+@item If that fails, generate an error
+@end enumerate
+
+
@c ---------------------------------------------------------------------
@c Extensions
@c ---------------------------------------------------------------------
+2015-03-11 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/65200
+ * gfortran.dg/open_errors.f90: Update checks for iomsg string.
+ * gfortran.dg/open_new_segv.f90: Fix error message pattern.
+
2015-03-11 Jakub Jelinek <jakub@redhat.com>
* c-c++-common/asan/no-asan-check-glob.c: Add -ffat-lto-objects
! PR30005 Enhanced error messages for OPEN
! Submitted by Jerry DeLisle <jvdelisle@gcc.gnu.org>
! See PR38956. Test fails on cygwin when user has Administrator rights
+! As of the fix for PR 65200, the error message is partly generated by
+! strerror*(), so can depend on the target and the locale, so check
+! only the beginning of the error string, which should be constant.
character(60) :: msg
character(25) :: n = "temptestfile"
logical :: there
msg=""
open(77,file=n,status="new", iomsg=msg, iostat=i)
if (i == 0) call abort()
-if (msg /= "File 'temptestfile' already exists") call abort()
+if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
open(77,file=n,status="old")
close(77, status="delete")
open(77,file=n,status="old", iomsg=msg, iostat=i)
if (i == 0) call abort()
-if (msg /= "File 'temptestfile' does not exist") call abort()
+if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
open(77,file="./", iomsg=msg, iostat=i)
-if (msg /= "'./' is a directory" .and. msg /= "Invalid argument") call abort()
+if (msg(1:23) /= "Cannot open file './': " &
+ .and. msg /= "Invalid argument") call abort()
open(77,file=n,status="new")
i = chmod(n, "-w")
close(77, status="keep")
open(77,file=n, iomsg=msg, iostat=i, action="write")
if (i == 0) call abort()
- if (msg /= "Permission denied trying to open file 'temptestfile'") call abort()
+ if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
endif
i = chmod(n,"+w")
! { dg-do run }
-! { dg-shouldfail "File already exists" }
+! { dg-shouldfail "Cannot open file" }
! PR 64770 SIGSEGV when trying to open an existing file with status="new"
program pr64770
implicit none
status="new")
end program pr64770
! { dg-output "At line 10 of file.*" }
-! { dg-output "Fortran runtime error: File .pr64770test.dat. already exists" }
+! { dg-output "Fortran runtime error: Cannot open file .pr64770test.dat.:" }
! { dg-final { remote_file build delete "pr64770test.dat" } }
+2015-03-11 Janne Blomqvist <jb@gcc.gnu.org>
+
+ PR libfortran/65200
+ * io/open.c (new_unit): Use gf_strerror rather than hardcoding
+ error messages for different errno values.
+ * io/unix.c (regular_file2): Handle EPERM in addition to EACCES.
+
2015-03-10 Alessandro Fanfarillo <fanfarillo.gcc@gmail.com>
Tobias Burnus <burnus@net-b.de>
s = open_external (opp, flags);
if (s == NULL)
{
+ char errbuf[256];
char *path = fc_strdup (opp->file, opp->file_len);
- size_t msglen = opp->file_len + 51;
+ size_t msglen = opp->file_len + 22 + sizeof (errbuf);
char *msg = xmalloc (msglen);
-
- switch (errno)
- {
- case ENOENT:
- snprintf (msg, msglen, "File '%s' does not exist", path);
- break;
-
- case EEXIST:
- snprintf (msg, msglen, "File '%s' already exists", path);
- break;
-
- case EACCES:
- snprintf (msg, msglen,
- "Permission denied trying to open file '%s'", path);
- break;
-
- case EISDIR:
- snprintf (msg, msglen, "'%s' is a directory", path);
- break;
-
- default:
- free (msg);
- msg = NULL;
- }
-
+ snprintf (msg, msglen, "Cannot open file '%s': %s", path,
+ gf_strerror (errno, errbuf, sizeof (errbuf)));
generate_error (&opp->common, LIBERROR_OS, msg);
free (msg);
free (path);
flags->action = ACTION_READWRITE;
return fd;
}
- if (errno != EACCES && errno != EROFS)
+ if (errno != EACCES && errno != EPERM && errno != EROFS)
return fd;
/* retry for read-only access */
return fd; /* success */
}
- if (errno != EACCES && errno != ENOENT)
+ if (errno != EACCES && errno != EPERM && errno != ENOENT)
return fd; /* failure */
/* retry for write-only access */