void regfile_iter_new(const char *dirname, struct regfile_iter **result)
{
- struct regfile_iter *iter = xmalloc(sizeof(*iter));
+ struct regfile_iter *iter;
+ DIR *dir = opendir(dirname);
- iter->dir = opendir(dirname);
- if (!iter->dir) {
- EMERG_LOG("opendir %s: %s\n", dirname, strerror(errno));
- exit(EXIT_FAILURE);
+ if (!dir) {
+ NOTICE_LOG("opendir %s: %s\n", dirname, strerror(errno));
+ *result = NULL;
+ return;
}
+ iter = xmalloc(sizeof(*iter));
+ iter->dir = dir;
iter->dfd = dirfd(iter->dir);
assert(iter->dfd >= 0);
regfile_iter_next(iter);
void *map;
const char *path;
- if (!iter->entry)
+ if (!iter || !iter->entry)
return false;
path = iter->entry->d_name;
ret = openat(iter->dfd, path, O_RDONLY, 0);
const char *regfile_iter_basename(const struct regfile_iter *iter)
{
- if (!iter->entry)
+ if (!iter || !iter->entry)
return NULL;
return iter->entry->d_name;
}
const struct stat *regfile_iter_stat(const struct regfile_iter *iter)
{
- return &iter->stat;
+ return iter? &iter->stat : NULL;
}
void regfile_iter_free(struct regfile_iter *iter)
{
+ if (!iter)
+ return;
closedir(iter->dir);
free(iter);
}