static dir_t *fetch_dir(const char *path) /* NOTE: if path is not empty, it must end with DIR_SEPERATOR */
{
- int rc;
DIR *dir;
- struct dirent dirent, *result;
+ struct dirent *dirent;
dir_t *head = NULL, *entry, **entryp = &head;
int count = 0;
dir_t **list;
return NULL;
}
while (1) {
- rc = readdir_r(dir, &dirent, &result);
- if (rc < 0)
+ dirent = readdir(dir);
+ if (dirent == NULL)
break;
- if (result == NULL)
- break;
- if (result->d_type != DT_REG && result->d_type != DT_LNK)
+ if (dirent->d_type != DT_REG && dirent->d_type != DT_LNK)
continue;
- entry = calloc(1, sizeof(dir_t) + strlen(path) + strlen(result->d_name) + 1);
+ entry = calloc(1, sizeof(dir_t) + strlen(path) + strlen(dirent->d_name) + 1);
if (!entry) {
fprintf(stderr, "no memory");
return NULL;
*entryp = entry;
entryp = &entry->next;
#ifdef DEBUG_FILENAME
- printf("Fetching entry: path='%s' filename='%s'\n", path, result->d_name);
+ printf("Fetching entry: path='%s' filename='%s'\n", path, dirent->d_name);
#endif
strcpy(entry->name, path);
- strcat(entry->name, result->d_name);
+ strcat(entry->name, dirent->d_name);
count++;
}
closedir(dir);