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
Status: RESOLVED FIXED
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
URL:
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:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-12-14 22:13:28


Attachments

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")
  close(nout)
  open(nout, file="foo.dat", status="new",err=100)  ! This should fail
  write(nout,*) "Hello"                     ! and not this.
100 continue
end
$ 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
--enable-languages=c,c++,f95
Thread model: posix
gcc version 4.0.0 20041212 (experimental)
Comment 2 Thomas Koenig 2005-01-01 22:07:44 UTC
Patch here:

http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00024.html
Comment 3 Thomas Koenig 2005-01-12 22:03:20 UTC
Sligtly updated patch:

http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00675.html

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

.. which was broken; http://gcc.gnu.org/ml/gcc-patches/2005-01/msg00024.html
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:

http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01056.html
Comment 6 CVS Commits 2005-01-22 19:49:23 UTC
Subject: Bug 18982

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pbrook@gcc.gnu.org	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  <Thomas.Koenig@online.de>
	
	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
	regular_file.
	testsuite/
	* gfortran.dg/open_new.f90: New file.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4924&r2=1.4925
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gfortran.dg/open_new.f90.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/ChangeLog.diff?cvsroot=gcc&r1=1.149&r2=1.150
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libgfortran/io/unix.c.diff?cvsroot=gcc&r1=1.19&r2=1.20

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