[PATCH] Fix for PR fortran/38956 - take 2

David Billinghurst dbcygwin@gmail.com
Sat Jan 31 12:45:00 GMT 2009


PR PR38956 is the failure of testsuite/gfortran.dg/chmod_{1,2,3}.f90 on i686-pc-cygwin.

The problem is due to a mismatch between Windows and POSIX file access models.
Under Windows, accounts with Administrator rights can write to any file
regardless of the file permission.  There is no easy way to check for this
from Fortran.

This is Take 2 of a patch for the problem.  The offending part of the test is
not compiled on cygwin.

2009-01-31  David Billinghurst (billingd@gcc.gnu.org)

     PR fortran/38956
     * gfortran.dg/chmod_1.f90: Conditionally compile test that fails on cygwin
     * gfortran.dg/chmod_2.f90: Likewise
     * gfortran.dg/chmod_3.f90: Likewise
     * gfortran.dg/open_errors.f90: Likewise


--- chmod_1.f90.orig    2009-01-31 22:45:29.890125000 +1100
+++ chmod_1.f90 2009-01-31 22:49:29.827625000 +1100
@@ -1,5 +1,5 @@
  ! { dg-do run { target { ! *-*-mingw* } } }
-! { dg-options "-std=gnu" }
+! { dg-options "-std=gnu -x f95-cpp-input" }
    implicit none
    character(len=*), parameter :: n = "foobar_file"
    integer :: i
@@ -19,10 +19,13 @@
      if (access(n,"x") /= 0 .or. access(n,"X") /= 0) call abort
    end if

+! Fails on *-*-cygwin if user has Administrator rights
+#ifndef __CYGWIN__
    call chmod (n, "a-w", i)
    if (i == 0 .and. getuid() /= 0) then
      if (access(n,"w") == 0 .or. access(n,"W") == 0) call abort
    end if
+#endif

    open (10,file=n)
    close (10,status="delete")

--- chmod_2.f90.orig    2009-01-31 22:45:35.624500000 +1100
+++ chmod_2.f90 2009-01-31 22:50:12.843250000 +1100
@@ -1,5 +1,5 @@
  ! { dg-do run { target { ! *-*-mingw* } } }
-! { dg-options "-std=gnu" }
+! { dg-options "-std=gnu -x f95-cpp-input" }
    implicit none
    character(len=*), parameter :: n = "foobar_file"
    integer :: i
@@ -19,10 +19,13 @@
      if (access(n,"x") /= 0 .or. access(n,"X") /= 0) call abort
    end if

+! Fails on *-*-cygwin if user has Administrator rights
+#ifndef __CYGWIN__
    i = chmod (n, "a-w")
    if (i == 0 .and. getuid() /= 0) then
      if (access(n,"w") == 0 .or. access(n,"W") == 0) call abort
    end if
+#endif

    open (10,file=n)
    close (10,status="delete")

--- chmod_3.f90.orig    2009-01-31 22:45:41.358875000 +1100
+++ chmod_3.f90 2009-01-31 22:49:27.108875000 +1100
@@ -1,5 +1,5 @@
  ! { dg-do run { target { ! *-*-mingw* } } }
-! { dg-options "-std=gnu -fdefault-integer-8" }
+! { dg-options "-std=gnu -fdefault-integer-8 -x f95-cpp-input" }
    implicit none
    character(len=*), parameter :: n = "foobar_file"
    integer :: i
@@ -19,10 +19,13 @@
      if (access(n,"x") /= 0 .or. access(n,"X") /= 0) call abort
    end if

+! Fails on *-*-cygwin if user has Administrator rights
+#ifndef __CYGWIN__
    i = chmod (n, "a-w")
    if (i == 0 .and. getuid() /= 0) then
      if (access(n,"w") == 0 .or. access(n,"W") == 0) call abort
    end if
+#endif

    open (10,file=n)
    close (10,status="delete")

--- open_errors.f90.orig        2009-01-31 22:54:53.952625000 +1100
+++ open_errors.f90     2009-01-31 22:54:13.030750000 +1100
@@ -1,4 +1,5 @@
  ! { dg-do run { target { ! *-*-mingw* } } }
+! { dg-options "-x f95-cpp-input" }
  ! PR30005 Enhanced error messages for OPEN
  ! Submitted by Jerry DeLisle  <jvdelisle@gcc.gnu.org>
  character(60) :: msg
@@ -25,12 +26,15 @@

  open(77,file=n,status="new")
  i = chmod(n, "-w")
+! Fails on *-*-cygwin if user has Administrator rights
+#ifndef __CYGWIN__
  if (i == 0 .and. getuid() /= 0) then
   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()
  endif
+#endif

  i = chmod(n,"+w")
  open(77,file=n, iomsg=msg, iostat=i, action="read")



More information about the Fortran mailing list