application: Speed up dir_get_info() further.
It's quite rare that it is called for a symlink to a directory. But it only needs a second syscall to stat() if that happened. Therefore speed up the common case by avoiding an unecessary second syscall. Change-Id: I911105f76631ebccc7696a1540e9cf069a706000
This commit is contained in:
parent
c27c3f10fd
commit
5fd8dd1321
1 changed files with 23 additions and 18 deletions
|
@ -300,26 +300,31 @@ struct dirinfo dir_get_info(DIR* _parent, struct dirent *dir)
|
|||
#endif
|
||||
snprintf(path, sizeof(path), "%s/%s", parent->path, dir->d_name);
|
||||
|
||||
if (!stat(path, &s))
|
||||
|
||||
if (!lstat(path, &s))
|
||||
{
|
||||
if (S_ISDIR(s.st_mode))
|
||||
ret.attribute |= ATTR_DIRECTORY;
|
||||
int err = 0;
|
||||
if (S_ISLNK(s.st_mode))
|
||||
{
|
||||
ret.attribute |= ATTR_LINK;
|
||||
err = stat(path, &s);
|
||||
}
|
||||
if (!err)
|
||||
{
|
||||
if (S_ISDIR(s.st_mode))
|
||||
ret.attribute |= ATTR_DIRECTORY;
|
||||
|
||||
ret.size = s.st_size;
|
||||
tm = localtime(&(s.st_mtime));
|
||||
}
|
||||
|
||||
if (!lstat(path, &s) && S_ISLNK(s.st_mode))
|
||||
ret.attribute |= ATTR_LINK;
|
||||
|
||||
if (tm)
|
||||
{
|
||||
ret.wrtdate = ((tm->tm_year - 80) << 9) |
|
||||
((tm->tm_mon + 1) << 5) |
|
||||
tm->tm_mday;
|
||||
ret.wrttime = (tm->tm_hour << 11) |
|
||||
(tm->tm_min << 5) |
|
||||
(tm->tm_sec >> 1);
|
||||
ret.size = s.st_size;
|
||||
if ((tm = localtime(&(s.st_mtime))))
|
||||
{
|
||||
ret.wrtdate = ((tm->tm_year - 80) << 9) |
|
||||
((tm->tm_mon + 1) << 5) |
|
||||
tm->tm_mday;
|
||||
ret.wrttime = (tm->tm_hour << 11) |
|
||||
(tm->tm_min << 5) |
|
||||
(tm->tm_sec >> 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue