libgfortran patch for fortran PR 18653

Steve Ellcey sje@cup.hp.com
Wed Dec 1 18:43:00 GMT 2004


Here is a patch to fix PR 18653, I tested it on IA64 HP-UX with no
regressions.  It causes read-only files to be opened with ACTION_READ or
write-only files to be opened with ACTION_WRITE when the user specified
action is ACTION_UNSPECIFIED.

I created two new wrappers in unix.c (file_is_readable,
file_is_writable) along the lines of the existing file_exists routine.

The current behaviour is a regression from g77 so I think it should be
OK to make this change for mainline.

OK to checkin?

Steve Ellcey
sje@cup.hp.com

2004-12-01  Steve Ellcey  <sje@cup.hp.com>

	* io/io.h (file_is_readable): New.
	(file_is_writable): Ditto.
	* io/unix.c (file_is_readable): Ditto.
	(file_is_writable): Ditto.
	* io/open.c (new_unit): Check file permissions
	when ACTION_UNSPECIFIED.

*** gcc.orig/libgfortran/io/io.h	Wed Dec  1 10:22:48 2004
--- gcc/libgfortran/io/io.h	Wed Dec  1 10:22:28 2004
*************** int delete_file (gfc_unit *);
*** 429,434 ****
--- 429,440 ----
  #define file_exists prefix(file_exists)
  int file_exists (void);
  
+ #define file_is_readable prefix(file_is_readable)
+ int file_is_readable (void);
+ 
+ #define file_is_writable prefix(file_is_writable)
+ int file_is_writable (void);
+ 
  #define inquire_sequential prefix(inquire_sequential)
  const char *inquire_sequential (const char *, int);
  
*** gcc.orig/libgfortran/io/unix.c	Wed Dec  1 10:22:58 2004
--- gcc/libgfortran/io/unix.c	Wed Dec  1 10:22:28 2004
*************** file_exists (void)
*** 1285,1290 ****
--- 1285,1327 ----
  }
  
  
+ /* file_is_readable()-- Returns nonzero if the current filename exists and
+    is readable on the system.  */
+ 
+ int
+ file_is_readable (void)
+ {
+   char path[PATH_MAX + 1];
+   struct stat statbuf;
+ 
+   if (unpack_filename (path, ioparm.file, ioparm.file_len))
+     return 0;
+ 
+   if (access (path, R_OK) < 0)
+     return 0;
+ 
+   return 1;
+ }
+ 
+ 
+ /* file_is_writable()-- Returns nonzero if the current filename exists and
+    is readable on the system.  */
+ 
+ int
+ file_is_writable (void)
+ {
+   char path[PATH_MAX + 1];
+   struct stat statbuf;
+ 
+   if (unpack_filename (path, ioparm.file, ioparm.file_len))
+     return 0;
+ 
+   if (access (path, W_OK) < 0)
+     return 0;
+ 
+   return 1;
+ }
+ 
  
  static const char *yes = "YES", *no = "NO", *unknown = "UNKNOWN";
  
*** gcc.orig/libgfortran/io/open.c	Wed Dec  1 10:22:54 2004
--- gcc/libgfortran/io/open.c	Wed Dec  1 10:22:28 2004
*************** new_unit (unit_flags * flags)
*** 259,266 ****
    if (flags->access == ACCESS_UNSPECIFIED)
      flags->access = ACCESS_SEQUENTIAL;
  
!   if (flags->action == ACTION_UNSPECIFIED)
!     flags->action = ACTION_READWRITE;	/* Processor dependent.  */
  
    if (flags->form == FORM_UNSPECIFIED)
      flags->form = (flags->access == ACCESS_SEQUENTIAL)
--- 259,273 ----
    if (flags->access == ACCESS_UNSPECIFIED)
      flags->access = ACCESS_SEQUENTIAL;
  
!   if (flags->action == ACTION_UNSPECIFIED)	/* Processor dependent.  */
!     {
!       if (file_exists() && file_is_readable() && !file_is_writable())
!         flags->action = ACTION_READ;
!       else if (file_exists() && file_is_writable() && !file_is_readable())
!         flags->action = ACTION_WRITE;
!       else
!         flags->action = ACTION_READWRITE;
!     }
  
    if (flags->form == FORM_UNSPECIFIED)
      flags->form = (flags->access == ACCESS_SEQUENTIAL)



More information about the Gcc-patches mailing list