$ cat open+write.f90 program main character(len=10) a call system("rm -f asdf.dat; touch asdf.dat; chmod u-w asdf.dat") open(file="asdf.dat",unit=10,err=999,action="read") write(10,*,err=20) "Hello, world" print *,"write to read-only file succeeded" call abort 20 continue ! rewind(10) read(10,'(A)',end=30,err=999) a print *,"read from empty file succeeded" call abort 999 continue print *,"error reading from read-only file" call abort 30 continue print *,"Success!" end $ gfortran open+write.f90 $ ./a.out error reading from read-only file Aborted
Uncommenting the rewind statement leads to $ ./a.out read from empty file succeeded Aborted $ gfortran -v ; gfortran -dumpmachine Using built-in specs. Configured with: ../gcc-4.0-20050109/configure --prefix=/home/zfkts --enable-languages=c,c++,f95 Thread model: posix gcc version 4.0.0 20050109 (experimental) ia64-unknown-linux-gnu -- Summary: Some read and write confusion with a read-only file Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P2 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Thomas dot Koenig at online dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19451