Avoid an extra stat per file, if possible, also when counting the
files for initial indexing.
{
struct dirent *entry = NULL;
char *next;
{
struct dirent *entry = NULL;
char *next;
struct dirent **fs_entries = NULL;
int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
struct dirent **fs_entries = NULL;
int num_fs_entries = scandir (path, &fs_entries, 0, dirent_sort_inode);
int i = 0;
if (num_fs_entries == -1) {
int i = 0;
if (num_fs_entries == -1) {
- stat (next, &st);
-
- if (S_ISREG (st.st_mode)) {
+ entry_type = dirent_type (path, entry);
+ if (entry_type == S_IFREG) {
*count = *count + 1;
if (*count % 1000 == 0) {
printf ("Found %d files so far.\r", *count);
fflush (stdout);
}
*count = *count + 1;
if (*count % 1000 == 0) {
printf ("Found %d files so far.\r", *count);
fflush (stdout);
}
- } else if (S_ISDIR (st.st_mode)) {
+ } else if (entry_type == S_IFDIR) {
count_files (next, count, state);
}
count_files (next, count, state);
}