https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65200
--- Comment #3 from Janne Blomqvist <jb at gcc dot gnu.org> --- Untested patch: Index: io/open.c =================================================================== --- io/open.c (revision 221202) +++ io/open.c (working copy) @@ -502,34 +502,12 @@ s = open_external (opp, flags); if (s == NULL) { + char tmpmsg[256]; char *path = fc_strdup (opp->file, opp->file_len); - size_t msglen = opp->file_len + 51; + size_t msglen = opp->file_len + 22 + 256; 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, tmpmsg, 256)); generate_error (&opp->common, LIBERROR_OS, msg); free (msg); free (path); Index: io/unix.c =================================================================== --- io/unix.c (revision 221202) +++ io/unix.c (working copy) @@ -1353,7 +1353,7 @@ 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 */ @@ -1369,7 +1369,7 @@ return fd; /* success */ } - if (errno != EACCES && errno != ENOENT) + if (errno != EACCES && errno != EPERM && errno != ENOENT) return fd; /* failure */ /* retry for write-only access */ It also fixes a wart in io/open.c, where we previously hardcoded error messages for a few errno values, which is a bit silly as strerror{_l,_r} already provides a mapping from errno -> string. Still TODO: Docs about the processor dependent behavior when opening files with no ACTION= specifier. Fortran 2008, 9.5.6.4 (ACCESS= specifier in OPEN statement): "If this specifier is omitted, the default value is processor dependent."