2 ! { dg-additional-sources read_dir-aux.c }
11 integer(c_int
) function expect_open_to_fail () bind(C
)
14 subroutine my_verify_not_exists(s
) bind(C
)
15 ! Aborts if the passed pathname (still) exists
17 character(len
=1,kind
=c_char
) :: s(*)
19 subroutine my_mkdir(s
) bind(C
)
20 ! Call POSIX's mkdir - and ignore fails due to
21 ! existing directories but fail otherwise
23 character(len
=1,kind
=c_char
) :: s(*)
25 subroutine my_rmdir(s
) bind(C
)
26 ! Call POSIX's rmdir - and ignore fails
28 character(len
=1,kind
=c_char
) :: s(*)
32 character(len
=*), parameter :: sdir
= "junko.dir"
33 character(len
=*,kind
=c_char
), parameter :: c_sdir
= sdir
// c_null_char
38 if (expect_open_to_fail () /= 0) then
39 ! Windows is documented to fail with EACCESS when trying to open a
40 ! directory. However, target macros such as __WIN32__ are not defined
41 ! in Fortran; hence, we use a detour via this C function.
42 ! Check for '.' which is a known-to-exist directory:
43 open(unit
=10, file
='.',iostat
=ios
,action
='read',access
='stream')
45 stop 3 ! Error: open to fail (EACCESS)
50 open(unit
=10, file
=sdir
,iostat
=ios
,action
='read',access
='stream')
56 read(10, iostat
=ios
) c
57 if (ios
.ne
.21.and
.ios
.ne
.0) then ! EISDIR has often the value 21
58 close(10, status
='delete')
59 call my_verify_not_exists(c_sdir
)
62 close(10, status
='delete')
63 call my_verify_not_exists(c_sdir
)