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:
parent
1719169604
commit
80f722e97c
|
@ -61,13 +61,18 @@ opendir (const char *name)
|
|||
set_errno (fh->error ());
|
||||
res = NULL;
|
||||
}
|
||||
else if (fh->exists ())
|
||||
res = fh->opendir (-1);
|
||||
else
|
||||
else if (!fh->exists ())
|
||||
{
|
||||
set_errno (ENOENT);
|
||||
res = NULL;
|
||||
}
|
||||
else if (!fh->pc.isdir ())
|
||||
{
|
||||
set_errno (ENOTDIR);
|
||||
res = NULL;
|
||||
}
|
||||
else
|
||||
res = fh->opendir (-1);
|
||||
|
||||
if (!res && fh)
|
||||
delete fh;
|
||||
|
|
|
@ -2156,9 +2156,7 @@ fhandler_disk_file::opendir (int fd)
|
|||
DIR *dir;
|
||||
DIR *res = NULL;
|
||||
|
||||
if (!pc.isdir ())
|
||||
set_errno (ENOTDIR);
|
||||
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
|
||||
if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
|
||||
set_errno (ENOMEM);
|
||||
else if ((dir->__d_dirname = (char *) malloc ( sizeof (struct __DIR_cache)))
|
||||
== NULL)
|
||||
|
|
|
@ -45,9 +45,7 @@ fhandler_virtual::opendir (int fd)
|
|||
DIR *res = NULL;
|
||||
size_t len;
|
||||
|
||||
if (!virt_ftype_isdir (exists ()))
|
||||
set_errno (ENOTDIR);
|
||||
else if ((len = strlen (get_name ())) > PATH_MAX - 3)
|
||||
if ((len = strlen (get_name ())) > PATH_MAX - 3)
|
||||
set_errno (ENAMETOOLONG);
|
||||
else if ((dir = (DIR *) malloc (sizeof (DIR))) == NULL)
|
||||
set_errno (ENOMEM);
|
||||
|
|
Loading…
Reference in New Issue