1! { dg-do run { target { ! { *-*-mingw* *-*-cygwin* spu-*-* } } } }
2! PR30005 Enhanced error messages for OPEN
3! Submitted by Jerry DeLisle  <jvdelisle@gcc.gnu.org>
4! See PR38956.  Test fails on cygwin when user has Administrator rights
5! As of the fix for PR 65200, the error message is partly generated by
6! strerror*(), so can depend on the target and the locale, so check
7! only the beginning of the error string, which should be constant.
8character(60) :: msg
9character(25) :: n = "temptestfile"
10logical :: there
11inquire(file=n, exist=there)
12if (.not.there) then
13  open(77,file=n,status="new")
14  close(77, status="keep")
15endif
16msg=""
17open(77,file=n,status="new", iomsg=msg, iostat=i)
18if (i == 0) call abort()
19if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
20
21open(77,file=n,status="old")
22close(77, status="delete")
23open(77,file=n,status="old", iomsg=msg, iostat=i)
24if (i == 0) call abort()
25if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
26
27open(77,file="./", iomsg=msg, iostat=i)
28if (msg(1:23) /= "Cannot open file './': " &
29     .and. msg /= "Invalid argument") call abort()
30
31open(77,file=n,status="new")
32i = chmod(n, "-w")
33if (i == 0 .and. getuid() /= 0) then
34 close(77, status="keep")
35 open(77,file=n, iomsg=msg, iostat=i, action="write")
36 if (i == 0) call abort()
37 if (msg(1:33) /= "Cannot open file 'temptestfile': ") call abort()
38endif
39
40i = chmod(n,"+w")
41open(77,file=n, iomsg=msg, iostat=i, action="read")
42close(77, status="delete")
43end
44