The following program:

      OPEN(UNIT=1,FILE='noot',STATUS='NEW')
      END

when compiled/linked into a.out and run as follows:

$ rm aap
$ ln -s aap noot
$ ./a.out

gives:

At line 1 of file a.f (unit = 1, file = '')
Fortran runtime error: File 'noot' already exists

Other compilers (tested: xlf (IBM) and ifort (Intel)) permit to open a
non-existing file as 'NEW' this way.

The reason our run-time library doesn't is that in io/unix.c, we open a 'NEW'
file with open(...., O_CREAT | O_EXCL, ...).

The man page of open says about O_EXCL:

       O_EXCL

Ensure  that  this  call creates the file: if this flag is specified in
conjunction with O_CREAT, and pathname already exists, then open() will fail.
The behavior of O_EXCL is undefined if O_CREAT is not specified.

When these two flags are specified, symbolic links are not followed: if
pathname is a symbolic link, then open() fails regardless of where the
symbolic link points to.


-- 
           Summary: OPEN, STATUS='NEW' of a symbolic link to a non-existing
                    file fails.
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: toon at moene dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41387

Reply via email to