User account creation filtered due to spam.

Bug 18982 - open(status="new") does not generate an error if the file exists
Summary: open(status="new") does not generate an error if the file exists
Alias: None
Product: gcc
Classification: Unclassified
Component: libfortran (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
Keywords: patch
Depends on:
Blocks: 19292
  Show dependency treegraph
Reported: 2004-12-14 13:30 UTC by Thomas Koenig
Modified: 2005-01-22 22:33 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2004-12-14 22:13:28


Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2004-12-14 13:30:05 UTC
$ cat open.f90
  nout = 10
  open(nout, file="foo.dat", status="new")
  open(nout, file="foo.dat", status="new",err=100)  ! This should fail
  write(nout,*) "Hello"                     ! and not this.
100 continue
$ rm -f foo.dat
$ gfortran open.f90
$ ./a.out
At line 5 of file open.f90
Fortran runtime error: Cannot write to file opened for READ
Comment 1 Thomas Koenig 2004-12-14 13:30:42 UTC
I forget...

$ gfortran -v
Reading specs from /home/zfkts/lib/gcc/ia64-unknown-linux-gnu/4.0.0/specs
Configured with: ../gcc-4.0-20041212/configure --prefix=/home/zfkts
Thread model: posix
gcc version 4.0.0 20041212 (experimental)
Comment 2 Thomas Koenig 2005-01-01 22:07:44 UTC
Patch here:
Comment 3 Thomas Koenig 2005-01-12 22:03:20 UTC
Sligtly updated patch:

Comment 4 Thomas Koenig 2005-01-13 22:14:08 UTC
(In reply to comment #3)
> Sligtly updated patch:

.. which was broken;
was correct (although it fails due to whitespace changes).

This patch does not fix all that's broken, though.  The following
test cases still fail with my patch:

program open_readonly
  call system("touch tst2.dat ; chmod 100 tst2.dat")
  open(unit=10,file="tst2.dat", err=9000)
  goto 30
9000 continue
  print *,"Opening read-only file failed"
  call abort
30 continue
end program open_readonly

program open_writeonly
  call system("touch tst1.dat ; chmod 200 tst1.dat")
  open(unit=10,file="tst1.dat", err=9000)
  goto 30
9000 continue
  print *,"Opening write-only file failed"
  call abort
30 continue
end program open_writeonly

so something else is needed.

I've removed the "patch" keyword.
Comment 5 Thomas Koenig 2005-01-17 21:00:39 UTC
New patch:
Comment 6 CVS Commits 2005-01-22 19:49:23 UTC
Subject: Bug 18982

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2005-01-22 19:49:18

Modified files:
	gcc/testsuite  : ChangeLog 
	libgfortran    : ChangeLog 
	libgfortran/io : unix.c 
Added files:
	gcc/testsuite/gfortran.dg: open_new.f90 

Log message:
	2005-01-22  Thomas Koenig  <>
	PR libfortran/18982
	* io/unix.c (regular_file):  No need to change flags->action
	if an error occurs.  Document this.
	No need to call stat() for STATUS_OLD, open() will
	fail anyway.
	For ACTION_UNSPECIFIED, try open for read-write, then for
	read-only if open fails with EACCES, then for write-only
	if that fails with EACCES again.
	* io/unix.c (open_external): Document changed behavior of
	* gfortran.dg/open_new.f90: New file.


Comment 7 Paul Brook 2005-01-22 22:33:15 UTC