fstatat(2) is equivalent to stat(2), but it takes a file descriptor for
a directory, so that lookups are always relative to that file
descriptor. There's no need to construct a temporary std::string.
Commit migrated from https://github.com/dotnet/core-setup/commit/
6a6266a1ab4ba99b3c42b16cc8dc822db35fb45f
case DT_LNK:
case DT_UNKNOWN:
{
- std::string fullFilename;
-
- fullFilename.append(path);
- fullFilename.push_back(DIR_SEPARATOR);
- fullFilename.append(entry->d_name);
-
struct stat sb;
- if (stat(fullFilename.c_str(), &sb) == -1)
+
+ if (fstatat(dirfd(dir), entry->d_name, &sb, 0) == -1)
{
continue;
}