From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 6B7363858CDB; Wed, 20 Mar 2024 13:49:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B7363858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1710942592; bh=MWJrckSmE+4X4lImfS5gFzb7SzxrqOHK7aQaT5/HgYQ=; h=From:To:Subject:Date:From; b=Pwe0HO+DQog2VPu9c8mO3OU1Y+1RjBTYtB+p2WImz7gZUlyTcQyq6+nWAoyvz7/Rm 6FM6EpnqDq28aSsSbHMajj7alWTjTU3u1kBB+5RCpxtss9Y6fWJbL7kPNFvLP3Fuss tPpR6ZvdWz9M8bXwLfXPWkBDpPx1QIxuybYn8l3g= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: opendir(3): move ENOTDIR check into main function X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 17191696040a59dfbdc092d0ffe938a17039baed X-Git-Newrev: 80f722e97cf79b6ce64b2d665e059c5b7e15d416 Message-Id: <20240320134952.6B7363858CDB@sourceware.org> Date: Wed, 20 Mar 2024 13:49:52 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D80f722e97cf= 79b6ce64b2d665e059c5b7e15d416 commit 80f722e97cf79b6ce64b2d665e059c5b7e15d416 Author: Corinna Vinschen AuthorDate: Wed Mar 20 12:34:51 2024 +0100 Commit: Corinna Vinschen CommitDate: Wed Mar 20 12:34:51 2024 +0100 Cygwin: opendir(3): move ENOTDIR check into main function =20 So far the check for a directory is in the fhandler::opendir methods. Given that path_conv::check sets FILE_ATTRIBUTE_DIRECTORY on virtual files either, we can move the check up into the opendir(3) function. This avoids calling exists() twice when calling opendir(3). =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/dir.cc | 11 ++++++++--- winsup/cygwin/fhandler/disk_file.cc | 4 +--- winsup/cygwin/fhandler/virtual.cc | 4 +--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc index c30ed74d32b9..df0749197dbf 100644 --- a/winsup/cygwin/dir.cc +++ b/winsup/cygwin/dir.cc @@ -61,13 +61,18 @@ opendir (const char *name) set_errno (fh->error ()); res =3D NULL; } - else if (fh->exists ()) - res =3D fh->opendir (-1); - else + else if (!fh->exists ()) { set_errno (ENOENT); res =3D NULL; } + else if (!fh->pc.isdir ()) + { + set_errno (ENOTDIR); + res =3D NULL; + } + else + res =3D fh->opendir (-1); =20 if (!res && fh) delete fh; diff --git a/winsup/cygwin/fhandler/disk_file.cc b/winsup/cygwin/fhandler/d= isk_file.cc index c5b78984d72a..f1ac29d329ac 100644 --- a/winsup/cygwin/fhandler/disk_file.cc +++ b/winsup/cygwin/fhandler/disk_file.cc @@ -2156,9 +2156,7 @@ fhandler_disk_file::opendir (int fd) DIR *dir; DIR *res =3D NULL; =20 - if (!pc.isdir ()) - set_errno (ENOTDIR); - else if ((dir =3D (DIR *) malloc (sizeof (DIR))) =3D=3D NULL) + if ((dir =3D (DIR *) malloc (sizeof (DIR))) =3D=3D NULL) set_errno (ENOMEM); else if ((dir->__d_dirname =3D (char *) malloc ( sizeof (struct __DIR_ca= che))) =3D=3D NULL) diff --git a/winsup/cygwin/fhandler/virtual.cc b/winsup/cygwin/fhandler/vir= tual.cc index 21ff4f35ead1..4a0d29489e13 100644 --- a/winsup/cygwin/fhandler/virtual.cc +++ b/winsup/cygwin/fhandler/virtual.cc @@ -45,9 +45,7 @@ fhandler_virtual::opendir (int fd) DIR *res =3D NULL; size_t len; =20 - if (!virt_ftype_isdir (exists ())) - set_errno (ENOTDIR); - else if ((len =3D strlen (get_name ())) > PATH_MAX - 3) + if ((len =3D strlen (get_name ())) > PATH_MAX - 3) set_errno (ENAMETOOLONG); else if ((dir =3D (DIR *) malloc (sizeof (DIR))) =3D=3D NULL) set_errno (ENOMEM);