From: Tobias Burnus <tobias@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
fortran <fortran@gcc.gnu.org>, Jerry D <jvdelisle2@gmail.com>,
NightStrike <nightstrike@gmail.com>
Subject: Re: [Patch] gfortran.dg/read_dir.f90: Make PASS on Windows
Date: Mon, 19 Dec 2022 10:26:48 +0100 [thread overview]
Message-ID: <345db222-b459-6a2b-c8c4-c49808979594@codesourcery.com> (raw)
In-Reply-To: <c8e44598-adb6-8b3a-292b-6bef4622c86a@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]
And here is a more light-wight variant, suggested by Nightstrike:
Using '.' instead of creating a new directory - and checking for
__WIN32__ instead for __MINGW32__.
The only downside of this variant is that it does not check whether
"close(10,status='delete')" will delete a directory without failing with
an error. – If the latter makes sense, I think a follow-up check should
be added to ensure the directory has indeed been removed by 'close'.
Thoughts about which variant is better? Other suggestions or comments?
Tobias
PS: On my x86-64 Linux, OPEN works but READ fails with EISDIR/errno == 21.
On 19.12.22 10:09, Tobias Burnus wrote:
> As discussed in #gfortran IRC, on Windows opening a directory fails
> with EACCESS.
> (It works under Cygwin - nightstrike was so kind to test this.)
>
> Additionally, '[ -d dir ] || mkdir dir' is also not very portable.
>
> Hence, I use an auxiliary C file calling the POSIX functions and
> expect a fail for non-Cygwin windows.
>
> Comments? Suggestions? - If there aren't any, I plan to commit it
> as obvious tomorrow.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
[-- Attachment #2: fix-read_dir-var2.diff --]
[-- Type: text/x-patch, Size: 1667 bytes --]
gfortran.dg/read_dir.f90: Make PASS on Windows
Avoid call to the shell using POSIX syntax and use '.' instead.
Additionally, expect fail on non-Cygwin Windows as opening a directory
is documented to fail with EACCESS.
gcc/testsuite/ChangeLog:
* gfortran.dg/read_dir.f90: Open '.' instead of a freshly created
directory; expect error on Windows when opening a directory.
gcc/testsuite/gfortran.dg/read_dir.f90 | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/gcc/testsuite/gfortran.dg/read_dir.f90 b/gcc/testsuite/gfortran.dg/read_dir.f90
index c7ddc51fb90..c91d0f78413 100644
--- a/gcc/testsuite/gfortran.dg/read_dir.f90
+++ b/gcc/testsuite/gfortran.dg/read_dir.f90
@@ -1,20 +1,27 @@
! { dg-do run }
+! { dg-additional-options "-cpp" }
+!
! PR67367
+
program bug
implicit none
character(len=1) :: c
- character(len=256) :: message
integer ios
- call system('[ -d junko.dir ] || mkdir junko.dir')
- open(unit=10, file='junko.dir',iostat=ios,action='read',access='stream')
+ open(unit=10, file='.',iostat=ios,action='read',access='stream')
+
+#if defined(__WIN32__) && !defined(__CYGWIN__)
+ ! Windows is documented to fail with EACCESS when trying to open a directory
+ if (ios == 0) &
+ stop 3 ! Expected EACCESS
+ stop 0 ! OK
+#endif
+
if (ios.ne.0) then
- call system('rmdir junko.dir')
STOP 1
end if
read(10, iostat=ios) c
- if (ios.ne.21.and.ios.ne.0) then
- close(10, status='delete')
+ close(10)
+ if (ios.ne.21.and.ios.ne.0) then ! EISDIR has often the value 21
STOP 2
end if
- close(10, status='delete')
end program bug
next prev parent reply other threads:[~2022-12-19 9:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 9:09 Tobias Burnus
2022-12-19 9:26 ` Tobias Burnus [this message]
2022-12-19 10:51 ` Tobias Burnus
2022-12-21 7:18 ` Tobias Burnus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=345db222-b459-6a2b-c8c4-c49808979594@codesourcery.com \
--to=tobias@codesourcery.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jvdelisle2@gmail.com \
--cc=nightstrike@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).