4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 12:59:21 +08:00

Cygwin: opendir(3): move ENOTDIR check into main function

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).

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2024-03-20 12:34:51 +01:00
parent 1719169604
commit 80f722e97c
3 changed files with 10 additions and 9 deletions

View File

@ -61,13 +61,18 @@ opendir (const char *name)
set_errno (fh->error ()); set_errno (fh->error ());
res = NULL; res = NULL;
} }
else if (fh->exists ()) else if (!fh->exists ())
res = fh->opendir (-1);
else
{ {
set_errno (ENOENT); set_errno (ENOENT);
res = NULL; res = NULL;
} }
else if (!fh->pc.isdir ())
{
set_errno (ENOTDIR);
res = NULL;
}
else
res = fh->opendir (-1);
if (!res && fh) if (!res && fh)
delete fh; delete fh;

View File

@ -2156,9 +2156,7 @@ fhandler_disk_file::opendir (int fd)
DIR *dir; DIR *dir;
DIR *res = NULL; DIR *res = NULL;
if (!pc.isdir ()) if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
set_errno (ENOTDIR);
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
set_errno (ENOMEM); set_errno (ENOMEM);
else if ((dir->__d_dirname = (char *) malloc ( sizeof (struct __DIR_cache))) else if ((dir->__d_dirname = (char *) malloc ( sizeof (struct __DIR_cache)))
== NULL) == NULL)

View File

@ -45,9 +45,7 @@ fhandler_virtual::opendir (int fd)
DIR *res = NULL; DIR *res = NULL;
size_t len; size_t len;
if (!virt_ftype_isdir (exists ())) if ((len = strlen (get_name ())) > PATH_MAX - 3)
set_errno (ENOTDIR);
else if ((len = strlen (get_name ())) > PATH_MAX - 3)
set_errno (ENAMETOOLONG); set_errno (ENAMETOOLONG);
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL) else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
set_errno (ENOMEM); set_errno (ENOMEM);