This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, libgfortran] PR30005 Open errors (not/already exists etc.): show also the file name
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: Fortran List <fortran at gcc dot gnu dot org>
- Cc: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 03 Dec 2006 21:18:23 -0800
- Subject: [patch, libgfortran] PR30005 Open errors (not/already exists etc.): show also the file name
:ADDPATCH fortran:
Hi All,
This straight forward patch provides easier to understand error messages on file
open and includes the file path in the message so users will have a clue where
to look.
This is an enhancement and therefore should only go to trunk.
Regression tested on x86-64-linux.
I will work up a suitable test case.
If I hear no comments from anyone in the next few days, I will commit.
OK for trunk.
Jerry
2006-12-03 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/30005
* io/open.c: Add errno.h include.
(new_unit): Add new error messages with file name for file open.
Index: open.c
===================================================================
*** open.c (revision 119453)
--- open.c (working copy)
*************** Boston, MA 02110-1301, USA. */
*** 32,37 ****
--- 32,38 ----
#include <unistd.h>
#include <stdio.h>
#include <string.h>
+ #include <errno.h>
#include "libgfortran.h"
#include "io.h"
*************** new_unit (st_parameter_open *opp, gfc_un
*** 374,380 ****
s = open_external (opp, flags);
if (s == NULL)
{
! generate_error (&opp->common, ERROR_OS, NULL);
goto cleanup;
}
--- 375,411 ----
s = open_external (opp, flags);
if (s == NULL)
{
! char *path, *msg;
! path = (char *) gfc_alloca (opp->file_len + 1);
! msg = (char *) gfc_alloca (opp->file_len + 51);
! unpack_filename (path, opp->file, opp->file_len);
!
! switch (errno)
! {
! case ENOENT:
! st_sprintf (msg, "File '%s' does not exist", path);
! generate_error (&opp->common, ERROR_OS, msg);
! break;
!
! case EEXIST:
! st_sprintf (msg, "File '%s' already exists", path);
! generate_error (&opp->common, ERROR_OS, msg);
! break;
!
! case EACCES:
! st_sprintf (msg, "Permission denied trying to open file '%s'", path);
! generate_error (&opp->common, ERROR_OS, msg);
! break;
!
! case EISDIR:
! st_sprintf (msg, "'%s' is a directory", path);
! generate_error (&opp->common, ERROR_OS, msg);
! break;
!
! default:
! generate_error (&opp->common, ERROR_OS, NULL);
! }
!
goto cleanup;
}